如何单击带有 Selenium 和 Java 的按钮?
How to click on a button with Selenium and Java?
我试图点击 iframe 中的“不,谢谢”,但一直收到“预期条件失败:等待框架可用”
我的代码:
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();
初始加载页面后 iframe 确实需要一些时间才能弹出,但我在 20、30、40 和 60 等待,但它不起作用。
该元素不在任何 <iframe>
中。
要点击元素 不用谢 你需要诱导 for the elementToBeClickable()
and you can use the following :
使用XPATH
:
driver.get("http://www.qaclickacademy.com")
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='NO THANKS']"))).click();
我试图点击 iframe 中的“不,谢谢”,但一直收到“预期条件失败:等待框架可用”
我的代码:
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();
初始加载页面后 iframe 确实需要一些时间才能弹出,但我在 20、30、40 和 60 等待,但它不起作用。
该元素不在任何 <iframe>
中。
要点击元素 不用谢 你需要诱导 elementToBeClickable()
and you can use the following
使用
XPATH
:driver.get("http://www.qaclickacademy.com") new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='NO THANKS']"))).click();