在自动化跨浏览器测试时,我在主方法和子方法中都使用了驱动程序。在"System.setProperty("webdriver.chrome.driver","D:chromedriver_win32"行中显示语法错误由于
import org.openqa.selenium.chrome.ChromeDriver;
public class MyClass {
System.setProperty("webdriver.chrome.driver","D:\chromedriver_win32\chromedriver.exe");
static WebDriver driver = new ChromeDriver();
public static void main(String[] args) throws IO Exception {
driver.findElement(By.id("aaa")).clear();
-do-
String B = new MyClass().gettext("eeee");
}
driver.quit();
}
public String getIframe(String id) {
driver.findElement(By.id("ddd")).clear();
-do-
return A;
}
}
我通过修改如下代码来解决这个问题:
import org.openqa.selenium.chrome.ChromeDriver;
public class MyClass {
static Webdriver driver;
public static void main(String[] args) throws IO Exception {
System.setProperty("webdriver.chrome.driver","D:\chromedriver_win32\chromedriver.exe");
driver = new ChromeDriver();
driver.findElement(By.id("aaa")).clear();
-do-
String B = new MyClass().gettext("eeee");
}
driver.quit();
}
public String getIframe(String id) {
driver.findElement(By.id("ddd")).clear();
-do-
return A;
}
}
那么简单! !