我知道已经存在非常相似的问题,但是我是 Java/Selenium WebDriver 的初学者,最初是在 Selenium IDE 中创建的,然后将其导出为Java / JUnit4 / WebDriver并希望得到具体的帮助,因为我是'不确定我到底哪里出错了。当我作为Java Application运行时,我收到错误Selection does not contain a main type,当我作为Java Applet运行时,我收到错误Selection does not contain an applet。这是我的代码:
package com.exports.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Login {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://www.example.co.uk/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testLogin() throws Exception {
driver.get(baseUrl + "/123example/index.jsp");
// ERROR: Caught exception [ERROR: Unsupported command [getEval | prompt("Username: ") | ]]
driver.findElement(By.name("LoginText1")).clear();
element.sendKeys(user input);
//driver.findElement(By.name("LoginText1")).clear();
//driver.findElement(By.name("LoginText1")).sendKeys(_username);
// ERROR: Caught exception [ERROR: Unsupported command [getEval | prompt("Password: ") | ]]
driver.findElement(By.name("password1")).clear();
element.sendKeys(user input);
//driver.findElement(By.name("password1")).clear();
//driver.findElement(By.name("password1")).sendKeys(_password);
driver.findElement(By.cssSelector("img[alt=\"Login\"]")).click();
// ERROR: Caught exception [ERROR: Unsupported command [windowFocus | | ]]
driver.switchTo().window("CarrierNet Desktop");
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alert.getText();
} finally {
acceptNextAlert = true;
}
}
}
任何帮助是极大的赞赏。