简体   繁体   English

如何使用 Selenium 和 Java 单击确认按钮

[英]How to click on the Acknowledge Button using Selenium and Java

I have an Acknowledge button and I want to click it.我有一个确认按钮,我想点击它。 I have tried all the three methods listed below.我已经尝试了下面列出的所有三种方法。 But it is not working.但它不起作用。

driver.findElement(By.cssSelector("input.btn.btn.primary")).submit();
driver.findElement(By.xpath("//*[@id='content']/div[2]/div/input")).click();
driver.findElement(By.xpath("//*[@value='I Acknowledge' ")).click();

This is the HTML Of the page:这是页面的 HTML:

<input class="btn btn-primary" type="button" value="I Acknowledge">

Try with this css locator:试试这个 css 定位器:

input[class='btn btn-primary'][value='I Acknowledge']输入[class='btn btn-primary'][value='I Acknowledge']

To click on the I Acknowledge element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies :要单击I Acknowledge元素,您必须为elementToBeClickable()引入WebDriverWait ,您可以使用以下任一定位器策略

  • cssSelector : cssSelector

     new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.btn.btn-primary[value='I Acknowledge']"))).click();
  • xpath : xpath

     new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='btn btn-primary' and @value='I Acknowledge']"))).click();

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

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