0

A quick question. How do I click on the following button link using selenium in python? The button does not have any ID or value

<a href="/" login="" class="classname123">Login</a> == $0

I receive below mentioned error:

Unable to locate element: //input[@type="submit" and @title="login"]

Thanks!

1
  • you can use driver.find_element_by_class('classname123').click() Commented Feb 9, 2017 at 11:52

4 Answers 4

2

You can use search by link text to handle exact element:

login = driver.find_element_by_link_text('Login')
Sign up to request clarification or add additional context in comments.

Comments

1

The element is <a>, not <input>, doesn't have type attribute and it has text Login, not title login

//a[contains(., "Login")]

2 Comments

Thanks! This works. The firefox browser opens and click the button. Is this also possible at the background? (underwater) Or only by physical acces?
@Jessekraal Have a look at headless browser. It can be used for testing without opening actual browser (I never worked with them though).
1

What you have shared is <a> and your error is in <input> as your xpath saying

use following to click on that link

.//a[text()='Login']

or

.//a[@class='classname123'][text()='Login']

Comments

1

Try this way.

//a[contains(text(), 'Login')]

OR

Try this way using class attribute of a tag.

//a[@class='classname123']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.