0

I am trying to automate the fronttend website for the company I work for, but I am having problem trying to find this xpath, when I run the test case in pyhton I get the following :

"Selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/lc-app/lc-auth-app/top-menu-bar/div/div[2]/top-menu-bar-right-section/div/top-menu-bar-right-section-drop/div/div[2]/ul/li[2]/button/span "}"

********THIS is the xpath i currently have, see below please********

 *"/html/body/div/lc-app/lc-auth-app/top-menu-bar/div/div[2]/top-menu-bar-right-section/div/top-menu-bar-right-section-drop/div/div[2]/ul/li[2]/button/span"*

can I find this specific xpath? I have attached the pic of what Im trying to find.. the "activity" path, I need to be specific, but I cant get it to work activity xpath

3
  • for some reason that didn't work, still getting the same error message :( Commented Oct 2, 2019 at 14:19
  • Did you try the WebDriverWait option? Also check if element available inside any iframe? Commented Oct 2, 2019 at 14:26
  • share the DOM file along with your question. Commented Oct 2, 2019 at 14:31

1 Answer 1

1

Try the following Xpath.

//button[@class='top-menu-drop-link']/span[text()='Activity']

Python code:

driver.find_element_by_xpath("//button[@class='top-menu-drop-link']/span[text()='Activity']").click()

However it is best practice to use WebDriverWait And element_to_be_clickable()

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='top-menu-drop-link']/span[text()='Activity']"))).click()

Note: To execute WebDriverWait you need to import followings.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

1 Comment

Great answer. Always advisable to use relative XPath notation over absolute.

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.