Selenium Webdriver - Stale element exception when clicking on multiple dropdowns while HTML DOM doesn't change

前端 未结 1 1329
无人共我
无人共我 2020-12-02 03:12

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 opti

相关标签:
1条回答
  • 2020-12-02 03:28

    When you select Insurance Test Client then only you get the option Product Insurance, which essentially means the HTML DOM gets changed, which results in StaleElementException. To avoid that, once we select from the first dropdown, we need to induce some wait for the elements of the second dropdown to render in the HTML DOM. Then we will use Select Class to select an option. Try out the following code block:

    //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");
    
    0 讨论(0)
提交回复
热议问题