2015-05-04 114 views
0

在我的应用程序中,我有3个列表框,当我选择第一个列表框中的任何值时,生成按钮处于进行状态(按钮更改为旋转符号),相应的数据被加载剩余的列表框和生成按钮应该出现。对于这种状态,我写了像找出元素可见性

WebElement datarefresh_element = (new WebDriverWait(driver, 20)).until(ExpectedConditions.visibilityOfElementLocated 
(By.id("butGenerate"))); 


if(datarefresh_element.isDisplayed()==true) 
{ 

     System.out.println("Generate button is available"); 
} 
    Select Dimension_selection = new Select (driver.findElement(By.id("cbDimension"))); 
      Dimension_selection.selectByVisibleText("Net Flow"); 
      Dimension_selection.selectByVisibleText("Total Sales"); 

的代码,同时执行代码,如果条件满足,但是当我选择在第二个列表框中的数据,没有选择的数据。您能否请帮助/建议,我需要使用驱动程序中的替代预期条件来查找元素。

+1

请编辑您的问题添加你在哪里更新的选择标准代码以及列表框选择 – LittlePanda

+0

数据的代码部分 – Krishna

+1

你说有3个下拉菜单吧?那么你应该有三个'Select'对象。我不知道为什么你会首先选择'Net Flow',然后尝试从同一个下拉列表中选择'Total Sales'。 – LittlePanda

回答

0

您所述的问题在注释部分得到了解答。有3个不同的列表框,因此你需要3个不同的元素。

因此,您可以为3个不同的列表框使用相同的元素,它只表示第一个列表框。

希望他们也有自己独特的名称或ID。

Select Dimension_selection2 = new Select (driver.findElement(By.id("name of second box"))); 
Dimension_selection2.selectByVisibleText("Net Flow"); 
+0

你必须创建一个新的选择Web元素。在我的旧回复中添加了一个示例 –

+0

我使用的唯一值仅用于标识元素,在第一个列表框中选择值时,生成按钮从按钮更改为正在处理的图像,此时其他两个选择框处于禁用状态。当数据被加载到剩余的盒子中时,进度图像被改变为生成按钮,这是确认数据被加载在盒子中,之后只有我可以选择第二个列表框中的值。 – Krishna

+0

好的。那么你需要等待你的下一个选择点击。 WebDriverWait等待; wait.until(ExpectedConditions.refreshed(ExpectedConditions.elementToBeClickable(通过))); –

0

每当你创建一个对象,并且如果对它做了任何修改/更新...再为它创建一个新对象。

WebElement dropDown1 = driver.findElement(By.id("dropDown1Id")) 
Select dropDown1Selection = new Select(dropDown1); 
dropDown1Selection.selectByVisibleText("dd1Value"); 

//Now as you have done the selection of dropDown1 
//Add the code for wait so as the other dropdowns value are updated 

//Create object of second drop down now - after the selection of dropdown1 item 
WebElement dropDown2 = driver.findElement(By.id("dropDown2Id")) 
Select dropDown2Selection = new Select(dropDown2); 
dropDown2Selection.selectByVisibleText("dd2Value"); 

// If you are creating second dropdown object prior to updation (selection of an item from dropdown1) -- you will not to do the selection 
+0

仅为第二个下拉菜单创建新元素。它没有选择列表框中的值。第一个下拉列表是单选,第二个列表框是多选框。 – Krishna

+0

尝试再次创建对象>> WebElement dropDown2Second = driver.findElement(By.id(“dropDown2Id”))>>选择dropDown2SelectionSecond = new Select(dropDown2Second); >> dropDown2SelectionSecond .selectByVisibleText(“dd2Value2”); –