Am curious if anyone might know which Selenium locating element method would be used to identify the below html.
I am trying to locate and 'click'
button type="submit" tabindex="3" data-ng-click="login()" class="btn btn-default" data-ng-disabled="loginForm.$invalid" data-ng-class="{ 'gray': loginForm.$invalid }">Login</button
CodePudding user response:
It depends, if you know text is not gonna change, direct use text
//button[text()='Login']
or based on attributes
//button[@data-ng-click='login()']
You can combine these two like below :
//button[@data-ng-click='login()' and text()='Login']
PS : Please check in the dev tools
(Google chrome) if we have unique entry in HTML DOM
or not.
Steps to check:
Press F12 in Chrome
-> go to element
section -> do a CTRL F
-> then paste the xpath
and see, if your desired element
is getting highlighted with 1/1
matching node.
CodePudding user response:
You can following xpath,
- //button[@type='submit']
- //button[@data-ng-click='login()']
- //button[text()='login']
driver.findElement(By.xpath("//button[text()='X']")).click();