Java Selenium没有包含正确xpath下拉列表的此类元素异常
我有一个测试用例中的代码,它工作正常,但从一天到下一天它都停止工作,我不明白为什么Java Selenium没有包含正确xpath下拉列表的此类元素异常,java,selenium,user-interface,selenium-webdriver,automation,Java,Selenium,User Interface,Selenium Webdriver,Automation,我有一个测试用例中的代码,它工作正常,但从一天到下一天它都停止工作,我不明白为什么 @Test public void addAreaToSurvey() throws InterruptedException { SurveyPage surveyPage = basePageNavigation(); Thread.sleep(2000); int surveysNum = surveyPage.getRowsTable().si
@Test
public void addAreaToSurvey() throws InterruptedException {
SurveyPage surveyPage = basePageNavigation();
Thread.sleep(2000);
int surveysNum = surveyPage.getRowsTable().size();
int rowTable = (int)(Math.random() * (surveysNum - 1 + 1) + 1);
int numberOfLabels = surveyPage.getNumberOfLabels(rowTable).size();
surveyPage.getAssignAreaButton(rowTable).click();
Thread.sleep(5000);
new WebDriverWait(surveyPage.driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//body/div[3]/div[3]/div[1]/ul[1]")));
int RowsDropdownNum = surveyPage.getRowsLabelsAreaDropdown().size();
int random_int2 = (int)(Math.random() * (RowsDropdownNum - 1 + 1) + 1);
String nameAreaToAdd = surveyPage.getLabelsAreaDropdown(random_int2).getText();
surveyPage.getLabelsAreaDropdown(random_int2).click();
Thread.sleep(2000);
int rowNum2 = surveyPage.getRowsLabelsAreaDropdown().size();
int random_int3 = (int)(Math.random() * (rowNum2 - 1 + 1) + 1);
String nameBranchToAdd = surveyPage.getLabelsAreaDropdown(random_int3).getText();
surveyPage.getLabelsAreaDropdown(random_int3).click();
Actions action = new Actions(surveyPage.driver); //click outside dropdown to close it
if(rowTable > 8){
action.moveByOffset(200,500).click().perform();
}else{
action.moveByOffset(200,45).click().perform();
}
Thread.sleep(1000);
Assert.assertTrue(numberOfLabels == (surveyPage.getNumberOfLabels(rowTable).size() - 1));
Assert.assertTrue(surveyPage.getAreaLabelInTable(rowTable, numberOfLabels).getText().equals(nameAreaToAdd));
Assert.assertTrue(surveyPage.getBranchLabelInTable(rowTable, numberOfLabels).getText().equals(nameBranchToAdd));
}
错误发生在以下行中:
int RowsDropdownNum=surveyPage.getRowsLabelsAreaDropdown().size()
public List getRowsLabelsReadropdown(){return driver.findElements(RowsLabelsReadropdown);}
最后一个private By rowsLabelsAreaDropdown=By.xpath(“//body/div[3]/div[3]/div[1]/ul[1]/div”);
我已经研究了好几天,但我找不到任何东西,下拉列表是可见的,正确的定位器,我等待它加载,没有iframe。
有人知道会是什么吗
public List<WebElement> getRowsLabelsAreaDropdown(){ return driver.findElements(rowsLabelsAreaDropdown); }
final private By rowsLabelsAreaDropdown = By.xpath("//body/div[3]/div[3]/div[1]/ul[1]/div");