1

I tried to automate a scenario, where the condition is that I have to select an option from drop down and then there's another dropown next to it, I have to click one option from next drop to enable to button . I tried with the code but it clicks only the first option,.And showing error as stale Element reference:element is not attached to the page document. Please help. Please let me know if in not very clear.

enter image description here

4

1 回答 1

2

当您选择Insurance Test Clientthen 时,只有您获得选项Product Insurance,这实质上意味着 HTML DOM 被更改,从而导致StaleElementException. 为避免这种情况,一旦我们从第一个下拉列表中进行选择,我们需要为wait第二个下拉列表的元素引入一些以在HTML DOM. 然后我们将使用SelectClass 来选择一个选项。试试下面的代码块:

//Select Channel 
Select oSelectChannel = new Select(driver.findElement(By.id("client"))); 
oSelectChannel.selectByVisibleText("Insurance Test Client"); 

WebDriverWait wait5 = new WebDriverWait(driver, 10);
wait5.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_a_Category_item")));

//Select Category 
Select oSelectCategory = new Select(driver.findElement(By.xpath("//*[@id='category']"))); 
oSelectCategory.selectByVisibleText("Product Insurance");
于 2017-07-12T13:14:12.977 回答