0

I want to click this daily tasks link but here id and class name is not unique, My DOM element is:

enter image description here

I tried :

#My Restaurant Configuration MENU
  driver.find_element_by_xpath("//a[@class='x-btn name-container x-unselectable x-box-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon']//span[contains(text()='My Restaurant Configuration']").click()
  print("second sub link")

getting following error:

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //a[@class='x-btn name-container x-unselectable x-box-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon']//span[contains(text()='My Restaurant Configuration'] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a[@class='x-btn name-container x-unselectable x-box-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon']//span[contains(text()='Daily Tasks']' is not a valid XPath expression. (Session info: chrome=80.0.3987.163)

2 Answers 2

0
driver.find_element_by_xpath("//span[contains(text(), 'Daily Tasks')]"

try also this option

driver.find_element_by_id("button-1184-btnInnerEl")

also try installing an extension for chrome or opera called cropath, it is very useful when you are still learning

Sign up to request clarification or add additional context in comments.

1 Comment

As i mentioned id and class name is not unique so i couldnot use find_element_by_id. And this xpath also not working
0

Try this:

  driver.find_element_by_xpath("//a[@class='x-btn name-container x-unselectable x-box-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon']//span[contains(text(), 'Daily Tasks')]").click()

4 Comments

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: The result of the xpath expression "//a[@class='x-btn name-container x-unselectable x-box-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon']//span/text()[contains(.,'Daily Tasks')]" is: [object Text]. It should be an element.
@DivyaMani - See edited answer and let me know if it works.
Please i updated my question with your findings.Please correct my code
@DivyaMani Don't know what to say; it's definitely a valid xpath expression.

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.