-1

I am trying to click the button first which I did and then the dropdown menu element which is Tüm Soru Tipleri automatically in Selenium Java.

This one is didn't work:

driver.findElement(By.id("select2-question_types-sq-result-xih0--1")).click();

Could you help?

HTML snapshot:

enter image description here

Element snapshot:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Sena
  • 37
  • 5

2 Answers2

0

Try adding a wait of 2 ms between button and drop-down.

0

Once you click and expand the further to click() on the desired <li> element with text as Tüm Soru Tipleri you need to induce WebDriverWait for the elementToBeClickable() and you can use the following locator strategy:

  • Using xpath and text():

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='select2-results']/ul[@id='select2-question_types-sq-results']//li[text()='Tüm Soru Tipleri']"))).click();
    
  • Using xpath and contains():

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='select2-results']/ul[@id='select2-question_types-sq-results']//li[contains(., 'Tüm Soru Tipleri')]"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352