Ashfi Fahad nm
Ashfi Fahad nm

Reputation: 23

How can I provide "driver.find_element" for the button in Selenium

I am a beginner in Selenium and Python, writing my first code to log in to a specified website and got stuck with the button part, not sure how to give an XPath to the below button code.

<button class="js-tfaLoginButton Button Button--pill Button--action Loadable u-marginBottomStandard u-size1of2 u-cursorPointer u-outlineNone" type="submit" data-qa="submit_login">
    Sign In
</button>

Tried out the below XPath but doesn't work:

/button[@class="js-tfaLoginButton Button Button--pill Button--action Loadable u-marginBottomStandard u-size1of2 u-cursorPointer u-outlineNone"]@class

Or is there any other method instead of XPath?

Thank you.

Upvotes: 1

Views: 4318

Answers (2)

E V N Raja
E V N Raja

Reputation: 110

We have the following ways to identify the element in the browser

ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"

Out of the above ways to locate element. We can use tagname or value(text) present inside the tag, like this:

XPATH:

driver.find_elements(By.XPATH, '//button[contains(text(), "Sign In"]')

or

driver.find_element(By.XPATH, '//button[text()="Sign In"]')

TAG_NAME:

driver.find_elements(By.TAG_NAME, '//button')

Upvotes: 1

Ratmir Asanov
Ratmir Asanov

Reputation: 6459

The correct XPath is:

//button[@class="js-tfaLoginButton Button Button--pill Button--action Loadable u-marginBottomStandard u-size1of2 u-cursorPointer u-outlineNone"]

Hope it helps you!

Upvotes: 1

Related Questions