当我在第11行调用System.setProperty()时出现此错误
Multiple markers at this line - Syntax error on token ",", < expected - Syntax error, insert ")" to complete MethodDeclaration - Syntax error, insert "Identifier (" to complete MethodHeaderName - Syntax error, insert "SimpleName" to complete QualifiedName - Syntax error on token ".", @ expected after this token
我知道我的chromedriver.exe的路径是正确的,因为我查了一下。我认为这只是我的System.setProperty()的放置。
有人可以帮我解决这个问题,所以我没有收到错误
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
public class BugLogin {
System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
WebDriver chromeDriver = new ChromeDriver();
@BeforeTest
public void setup() throws Exception {
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("url");
}
public boolean bug() {
WebElement test = driver.findElement(By.id(""));
while(true){
if(test.getText().equals("text")){
driver.findElement(By.id(""));
driver.findElement(By.id("")).clear();
driver.findElement(By.id("")).sendKeys("text");
driver.findElement(By.id(""));
driver.findElement(By.id("")).clear();
driver.findElement(By.id("")).sendKeys("text");
driver.findElement(By.id("")).click();
break;
}
else{
driver.navigate().back();
return true;
}
}
return false;
}
}
答案 0 :(得分:1)
为什么不将您的设置放在setup
方法中?
@BeforeTest
public void setup() throws Exception {
System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
chromeDriver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("url");
}
答案 1 :(得分:0)
问题是由于以下声明:
System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
原因:您不能使用包含外部可执行代码的语句 类方法,只声明和初始化标识符 定义
定义ChromeDriver并在以后的@BeforeTest中初始化它可能会解决您的问题。
WebDriver chromeDriver;
@BeforeTest
public void setup() throws Exception {
System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
chromeDriver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("url");
}