gpt4 book ai didi

java - eclipse 错误 : 'Selection does not contain a main type/an applet'

转载 作者:行者123 更新时间:2023-11-29 09:04:39 28 4
gpt4 key购买 nike

我知道已经有非常相似的问题,但是我是 Java/Selenium WebDriver 的初学者,最初是在 Selenium IDE 中创建的,然后将其导出为 Java/JUnit4/WebDriver 和希望得到具体的帮助,因为我不确定我到底哪里出错了。当我作为 Java 应用程序 运行时,出现错误 Selection does not contain a main type 并且当我作为 Java Applet 运行时,出现错误 < em>选择不包含小程序。这是我的代码:

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;
}
}
}

非常感谢任何帮助。

最佳答案

而不是将其作为 Java 应用程序运行。

将其作为 JUNIT 测试运行。

关于java - eclipse 错误 : 'Selection does not contain a main type/an applet' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15679173/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com