-1
A
回答
1
public class StackOverFlow {
@Test
public static void keepClicking(){
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.quackit.com/html/codes/html_radio_button.cfm");
List<WebElement> radios = driver.findElements(By.xpath("//*[@id='contentbar']/div/table[1]//input[@type='radio']"));
for (int i = 0; i < radios.size(); i++) {
// if you are getting stale element exception because of the page reload
radios = driver.findElements(By.xpath("//*[@id='contentbar']/div/table[1]//input[@type='radio']"));
System.out.println(radios.get(i).getAttribute("value"));
// select your radio and click to go to next page
radios.get(i).click();
driver.findElement(By.xpath("//*[@id='contentbar']/div/table[1]/tbody/tr[2]/td[2]/form/input[4]")).click();
// come back to your main page
driver.findElement(By.xpath("//*[@id='contentbar']/div/p[2]/a")).click();
}
}
}
运行上面的代码检查 - 您有多个单选按钮,去到下一个页面,回到主界面,点击下一个电台 - 在一个循环。
0
你可以试试下面的代码:
WebDriver driver = new FirefoxDriver();
driver.navigate()
.to("https://www.garuda-indonesia.com/other-countries/en/index.page");
driver.manage().window().maximize();
driver.findElement(By.id("ui-id-4")).click();
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(
ExpectedConditions.visibilityOfElementLocated(By
.id("originairportcode"))).sendKeys("j");
wait.until(
ExpectedConditions.visibilityOfElementLocated(By
.cssSelector("div#autocomplete-originairportcode ul#ui-id-9 li#CGK a")))
.click();
driver.findElement(By.id("destairportcode")).sendKeys("bali");
;
wait.until(
ExpectedConditions.visibilityOfElementLocated(By
.cssSelector("div#autocomplete-destairportcode ul#ui-id-16 li#DPS a")))
.click();
driver.findElement(By.id("departuredate")).click();
List<WebElement> ddate = driver.findElements(By
.cssSelector("a.ui-state-default"));
for (WebElement dd : ddate) {
if (dd.getText().equals("30")) {
dd.click();
}
}
driver.findElement(By.id("arrivaldate")).click();
driver.findElement(By.cssSelector("a.ui-datepicker-next.ui-corner-all"))
.click();
List<WebElement> rdate = driver.findElements(By
.cssSelector("a.ui-state-default"));
for (WebElement dd : rdate) {
if (dd.getText().equals("31")) {
dd.click();
}
}
driver.findElement(By.id("inputFormBookFlight")).submit();
List<WebElement> allRadios = wait
.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By
.xpath("//div[@class='divtableResultsSD']/table/tbody/tr/td/table[@id='left']/tbody/tr/td/table/tbody/tr/td/input")));
driver.findElement(By.id("btnCheckPriceSdai")).click();
driver.navigate().back();
//first radio button is already selected,start index with 1
for (int i = 1; i < allRadios.size(); i++) {
allRadios = wait
.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By
.xpath("//div[@class='divtableResultsSD']/table/tbody/tr/td/table[@id='left']/tbody/tr/td/table/tbody/tr/td/input")));
allRadios.get(i).click();
driver.findElement(By.id("btnCheckPriceSdai")).click();
driver.navigate().back();
}
driver.close();
}
相关问题
- 1. 递归循环Selenium Webdriver
- 2. Selenium WebDriver页面对象
- 3. Selenium webdriver 2.0中的页面加载 - java
- 4. 循环填充数据输入 - Selenium WebDriver
- 5. 从Selenium WebDriver执行页面的JavaScript
- 6. Selenium Webdriver循环控制,无限循环Java
- 7. Modal页面使用Selenium webdriver自动化
- 8. 使用Selenium Webdriver滚动页面
- 9. selenium-webdriver并等待页面加载
- 10. 使用selenium webdriver处理登录页面
- 11. For循环检查Selenium WebDriver中的项目列表
- 12. 在Python中刷新硒循环页面
- 13. CasperJS页面循环
- 14. 使用分页(Selenium webdriver C#)
- 15. 如何在Selenium WebDriver的页面对象(PageFactory)中使用数组?
- 16. 如何从Selenium Webdriver中的Frame导航回当前页面
- 17. 如何使用selenium webdriver验证页面中存在的行数
- 18. Selenium Webdriver:如何获取当前页面中的所有cookies
- 19. Selenium WebDriver中的页面对象模式是什么?
- 20. 在selenium Webdriver中设置环路参数
- 21. python中的selenium webdriver
- 22. selenium中的sendKeys()WebDriver
- 23. Selenium - webdriver测试if-else循环卡住/出错
- 24. Selenium :: WebDriver :: Error :: ElementNotVisibleError当循环点击使用Watir按钮
- 25. 页面标题在selenium webdriver中未正确捕获
- 26. 在Selenium Webdriver中显式触发页面加载阻塞
- 27. 在WebDriver中加载页面之前删除部分HTML - Selenium&Python
- 28. 如何使用selenium webdriver在Firefox,Chrome,PhantomJS中保存页面?
- 29. Selenium IDE - sideflow.js循环
- 30. Selenium Webdriver
这是不是最好的解决办法,但作为一种解决方法,你可以在一个外部文件的单选按钮,所有的定位器存储诸如财产或与它们对应的价格脱颖而出,你想验证。 您可以迭代一个循环,直到单选按钮的计数执行相同的操作。 –