我将从先前操作选项 id 中的 html 文件中获取,并将它们存储到一个列表中。
然后为列表中的每个成员尝试打开页面lile:www.xxx.xxx/en/account/service/SERVICEID
对于第一个有效元素页面已打开,但随后浏览器将停止任何活动......我会得到这个
org.openqa.selenium.StaleElementReferenceException:在缓存中找不到元素 - 页面可能在查找后已更改 命令持续时间或超时:3.28 秒
public class testy2{
private WebDriver driver;
private String baseUrl;
private List<WebElement> serviceList;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@BeforeClass
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://www.fastgsm.com";
// driver.manage().timeouts().pageLoadTimeout(120,TimeUnit.SECONDS);
}
@Test
public void test() throws Exception {
//Open page and set up login
driver.get(baseUrl + "/en/account/login");
driver.findElement(By.id("login")).clear();
driver.findElement(By.id("login")).sendKeys("selenium@account");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("1Selenium");
driver.findElement(By.id("password")).submit();
serviceList = driver.findElements(By.xpath("//select[@name='token_id']/option"));
for (WebElement service : serviceList) {
if(!service.getAttribute("value").contains("-")){
String test = service.getAttribute("value");
System.out.println("Checking service name : " + service.getAttribute("value") + ",on page " + (baseUrl + "/en/account/service/"+service.getAttribute("value")) );
driver.get(baseUrl + "/en/account/service/"+test);
System.out.println("Service name : " + service.getAttribute("value") +"status : OK");
}
else{
System.out.println("ERROR : INVALID SERVICE NAME");
}
}
}