0

I have written like this

repos=driver.find_elements_by_xpath('//a[@class="execute repo-list--repo-name"]')
choice=input()
ch=repos[choice-1].text
print ch #prints choice1
driver.find_element_by_xpath('//a[contains(text(),"%s"]' % ch).click()

for the HTML code

<a class="execute repo-list--repo-name" href="/vivek-puri/choice1">choice1</a>

But it is showing the error

The given selector //a[contains(text(),"choice1"] is either invalid or does not result in a WebElement.

Why it is showing such error although the element with text choice1 exits.

2
  • If you do not have other elements of with the class, use find_element_by_class_name instead Commented Feb 22, 2016 at 7:47
  • @LarsNielsen I have multiple elements Commented Feb 22, 2016 at 7:50

2 Answers 2

1

This is because of parentheses. You forgot second bracket: use

//a[contains(text(),"choice1")]

instead of

//a[contains(text(),"choice1"]
Sign up to request clarification or add additional context in comments.

1 Comment

driver.find_element_by_xpath('//a[contains(text(),"%s")]' % ch).click() is also not working
1

You are missing brackets after choice1 in the selector. It should be

//a[contains(text(),"choice1")]

You can also use by_link_text or by_partial_link_text

find_element_by_link_text('choice1')

find_element_by_partial_link_text('choice1')

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.