0

I have tried using selenium to automate a website and select a option from the drop-down menu, but the problem I am facing is that after the option is selected the ajax is not executed. This only happens when using selenium, I had tried this manually and it worked. Webdriver wait is not working for me. Here is the code that does that:

WebElement element =(driver.findElement(By.id("equity_optionchain_select")));
    Select elementSelect=new Select(element);
    elementSelect.selectByVisibleText("BANKNIFTY");
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • Take a look at this: https://stackoverflow.com/questions/20138761/how-to-select-a-dropdown-value-in-selenium-webdriver-using-java – Verity Dec 10 '20 at 09:59
  • @Verity my question is i am able to select the value from that drop-down menu but the ajax is not executed or the dom is not changed so i am not able to see the differences after selecting the value,the differences are visible when i use the website without selenium which means the dom changes ,i want it to change the dom when selenium is used. – Hitesh Tolani Dec 10 '20 at 10:08

1 Answers1

0

As far as BANKNIFTY is concerned, presumably those elements will be dynamic elements i.e. either JavaScript, ReactJS, jQuery, Ajax, Vue.js, Ember.js, GWT, etc. based elements. So ideally you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • Using id and selectByVisibleText():

    new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("equity_optionchain_select")))).selectByVisibleText("BANKNIFTY");
    
  • Using cssSelector and selectByVisibleText():

    new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("#equity_optionchain_select")))).selectByVisibleText("BANKNIFTY");
    
  • Using xpath and selectByVisibleText():

    new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='equity_optionchain_select']")))).selectByValue("BANKNIFTY");
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217