简体   繁体   中英

Unable to Click button in Selenium

Im having difficulties in locating an element which is a finish button within a page. I have used driver.findElementById("finish").click (); and it does not work.

Below are different examples I used but with no success:

for (WebElement Element : driver.findElement(By.id("finish")).findElements(By.tagName("a"))) {
if (Element.getAttribute ("class").contains("criteria-filter")) { Element.click();
break;
           }

----------------------------------------------------------------
 WebElement click1 = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"finish\"]")));   
((JavascriptExecutor) driver).executeScript("arguments[0].click();",click1);

----------------------------------------------------------------

if(!driver.findElementById("finish").isEnabled())
            {
driver.findElementById("finish").click();
 }else{
 System.out.println("False");
            }

Element:

   <a id="finish" access="" allof="PA.DEPLOYMENT_CONFIG" class="btn criteria-filter btn-success" href="" ng-click="verifyAllFields(sftpForm) &amp;&amp; sftpForm.$valid &amp;&amp; create()">Finish 
            </a>

Class selector is not the best idea as it will fail if there is more elements with the same class.

The best way is to open dev-tools, click ctrl + f, then try to cath your element by xpath like this:

//a[text()='Finish']

When you "cath" this browser will move to that element.

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