[英]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.我试图首先单击我所做的按钮,然后在 Selenium Java 中自动单击 Tüm Soru Tipleri的下拉菜单元素。
This one is didn't work:这个没用:
driver.findElement(By.id("select2-question_types-sq-result-xih0--1")).click();
Could you help?你能帮忙吗?
HTML snapshot: HTML 快照:
Element snapshot:元素快照:
尝试在按钮和下拉菜单之间添加 2 毫秒的等待。
Once you click and expand the dropdown 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 :一旦您单击并进一步展开下拉列表以click()在所需的<li>
元素上使用文本为Tüm Soru Tipleri您需要为elementToBeClickable()诱导WebDriverWait并且您可以使用以下定位器策略:
Using xpath and text()
:使用xpath和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()
:使用xpath和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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.