我正在尝试自动执行涉及下载月度报告的流程。
//Set Call handler
Select handlerdd = new Select(driver.findElement(By.cssSelector("#searchType")));
handlerdd.selectByValue("select");
//Wait
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//Search, choose is exactly as the filtering option
Select searchcriteriadd = new Select(driver.findElement(By.cssSelector("table.content-form:nth-child(1) > tbody:nth-child(1) > "
+ " tr:nth-child(1) > td:nth-child(1) > select:nth-child(2)")));
searchcriteriadd.selectByVisibleText("Is Exactly");
//Search box
WebElement search = driver.findElement(By.cssSelector("#searchString"));
search.sendKeys("File I Want");
search.sendKeys(Keys.ENTER);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Explicitly wait until element is seen
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("td.content-grid-th-delete > input:nth-child(1)")));
//Checkbox
driver.findElement(By.cssSelector("td.content-grid-th-delete > input:nth-child(1)")).click();
//Wait
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Generate Report button click
driver.findElement(By.cssSelector("fieldset.content-buttonbar:nth-child(10) > legend:nth-child(1) > button:nth-child(1)")).click();
该过程如下
从下拉菜单(handlerdd)中选择选项并显示搜索栏。
搜索过滤器设置为" IsExactly"和我正在寻找的文本"文件"发送到文本字段,然后输入。
我不完全确定问题是什么。可能发生的一件事(除了我的复选框不起作用)是在对文件进行勾选之前点击生成报告按钮。我不完全确定如何避免这个问题。我应该增加隐含的等待时间吗?
答案 0 :(得分:0)
在您的情况下,WebDriver会在加载过滤后的数据之前找到“生成报告”按钮。
您尝试使用Thread.sleep();
。以下代码可以帮助您。
//Set Call handler
Select handlerdd = new Select(driver.findElement(By.cssSelector("#searchType")));
handlerdd.selectByValue("select");
//Wait
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//Search, choose is exactly as the filtering option
Select searchcriteriadd = new Select(driver.findElement(By.cssSelector("table.content-form:nth-child(1) > tbody:nth-child(1) > "
+ " tr:nth-child(1) > td:nth-child(1) > select:nth-child(2)")));
searchcriteriadd.selectByVisibleText("Is Exactly");
//Search box
WebElement search = driver.findElement(By.cssSelector("#searchString"));
search.sendKeys("File I Want");
search.sendKeys(Keys.ENTER);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Explicitly wait until element is seen
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("td.content-grid-th-delete > input:nth-child(1)")));
//Checkbox
driver.findElement(By.cssSelector("td.content-grid-th-delete > input:nth-child(1)")).click();
Thread.sleep(7000);//You can specify time according to your load time
//Generate Report button click
driver.findElement(By.cssSelector("fieldset.content-buttonbar:nth-child(10) > legend:nth-child(1) > button:nth-child(1)")).click();
让我知道它是否有效。