2

I tried to click on a button. It has this structure:

HTML Code

<div class="button-wrapper" id="button-verify-wrapper">
       <a x-ng-click="verifySfdcConnection()" class="clearfix float-left button-green">
            <div class="icon-green icon-green-verify"></div>
            <div class="button-label ng-binding">Verify Connection</div>
        </a>
         <div x-ng-class="{'connection-verified':wizardData.inputSource.sfdc.connectionStatus}" x-ng-show="wizardData.inputSource.sfdc.connectionStatus" style="" class="connection-verified"></div>
      </div>

Any help how to do it? I tried this:

driver.findElement(By.xpath(".//*[@id='button-verify-wrapper']/a/div[1]")).click();

But it doesn't help. Thanks

Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
Oscar Ubillús
  • 150
  • 1
  • 2
  • 13
  • What do you mean it doesn't help?? Is there any exception?? And are you sure desired `div` element is clickable or `a` element is clickable?? – Saurabh Gaur Sep 21 '16 at 15:39
  • I Think is a link inside a Button.. just not exception, just don't click it. this is the button of the code: http://imgur.com/a/OmcDS – Oscar Ubillús Sep 21 '16 at 15:48

4 Answers4

0

You should click on the link using a css selector like:
a[x-ng-click*='verifySfdcConnection']

lauda
  • 4,153
  • 2
  • 14
  • 28
0

I think <a> element is clickable here. You should try to locate <a> element instead and perform click() action as below :-

  • using By.cssSelector() :-

    driver.findElement(By.cssSelector("div#button-verify-wrapper > a")).click();
    
  • using By.linkText() :-

    driver.findElement(By.linkText("Verify Connection")).click();
    
  • using By.xpath() :-

    driver.findElement(By.xpath(".//a[normalize-space(.) = 'Verify Connection']")).click();
    

If you're still unable to perform click, try as an alternate solution using JavascriptExecutor as below :-

((JavascriptExecutor)driver).executeScript("arguments[0].cli‌​ck()", driver.findElement(By.cssSelector("div#button-verify-wrapper > a")));
Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
  • I tried both, doesn't work. The curious here is... it haven't exception... i guess.... is clicking the text but not the real button. – Oscar Ubillús Sep 21 '16 at 16:13
  • But in provided HTML it clearly looks that click event is receiving by `a` element because JavaScript function `verifySfdcConnection()` is calling on `a` element on click event. – Saurabh Gaur Sep 21 '16 at 16:20
  • Try once using `JavascriptExecutor` to perform click as `((JavascriptExecutor)driver).executeScript("arguments[0].click()", driver.findElement(By.cssSelector("div#button-verify-wrapper > a")));` and let me know.. – Saurabh Gaur Sep 21 '16 at 16:23
  • It looks copy paste issue, try to type same manually and perform click and let me know.. – Saurabh Gaur Sep 21 '16 at 16:49
0

driver.findElement(By.id("button-verify-wrapper")).click();

Note: 1. if ID or class name is directly given no need to use xpath, can directly use By.id and By.class 2. To perform an action on web element we should know the properties of that element ex. if it is not a button you can not perform click on it

Asma
  • 16
  • 2
0

try this: $("#button-verify-wrapper > a").click()

M yalo
  • 1
  • 2