1

First question here.

Starting my journey on Selenium-Py, first assignment is to dissect a page with over 110.000 source code characters.

I need to find an element that's nested in 8 HTML tags which goes like:

<a href="#Menu" class="item item" onclick="JQueryModule('DBSearch', 'Send'); "> Search <\a>

Tried many ways to find the element, no matter how hard. Found many other items in the same exact page with things like:

elm = driver.find_element(By.XPATH, "//i[@onclick='openNav()']")
elm = driver.find_element(By.XPATH, "//div[@class='item active']/a[1]")

For some reason the same doesn't work here.

Any help?

1
  • Could you add more details on error. Commented Dec 8, 2022 at 5:14

1 Answer 1

1

Both Xpath you shared have wrong syntax.
The following will be better:

elm = driver.find_element(By.XPATH, "//i[@onclick='openNav()']")
elm = driver.find_element(By.XPATH, "//div[@class='item active']/a[1]")

But I can't be sure it will work since I can't check correctness and uniqueness of these locators. Also, possibly you will need to wait for page to be loaded before accessing elements. WebDriverWait expected_conditions explicit waits should be used for that.

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

3 Comments

First of all, thanks for the willingness to help. About the syntaxes, the code was on another workspace. They were indeed as you pointed out. Also, I'm pretty sure all the elements in the page are loaded since i added a manual wait input. Is there any other thing you can think of?
Sure, locator may be not unique or wrong. Element may be inside iframe, out of the visible view port etc. In order to give really working solution we need to see the link to the page you working on and all your selenium code.
Indeed, the item i tried to locate was inside an iframe. Thanks!

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.