简体   繁体   English

如何点击带有 Selenium 和 Java 的按钮?

[英]How to click on a button with Selenium and Java?

I am trying to click on the "NO THANKS" in the iframe but keep getting "Expected condition failed: waiting for frame to be available"我试图点击 iframe 中的“不,谢谢”,但不断收到“预期条件失败:等待框架可用”

My code:我的代码:

WebDriver driver = new ChromeDriver();
                                    
driver.get("http://www.qaclickacademy.com");

new WebDriverWait(driver,40).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt
(By.xpath("//div[@class='sumome-react-wysiwyg-popup-animation-group']")));
driver.findElement(By.xpath("//div[@class='sumome-react-wysiwyg-popup-animation-group']/span/div/div[6]/div//div/button")).click();

It does take some time for the iframe to popup after initial load of page but I had wait at 20,30,40 and 60 and it just doesn't work.初始加载页面后弹出 iframe 确实需要一些时间,但我在 20、30、40 和 60 等待,但它不起作用。

The element isn't with in any <iframe> .该元素不在任何<iframe>中。

To click on the element NO THANKS you need to induce WebDriverWait for the elementToBeClickable() and you can use the following Locator Strategy :要单击元素,不用了,您需要为elementToBeClickable elementToBeClickable()引入WebDriverWait ,您可以使用以下定位器策略

  • Using XPATH :使用XPATH

     driver.get("http://www.qaclickacademy.com") new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='NO THANKS']"))).click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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