简体   繁体   中英

How to click on the button with Java Selenium

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:

在此处输入图像描述

Element snapshot:

在此处输入图像描述

尝试在按钮和下拉菜单之间添加 2 毫秒的等待。

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM