0

I'm trying to parse some elements using XPATH

This is my python code:

driver.get("http://watir.com/examples/shadow_dom.html")
shadow_host = driver.find_element(By.XPATH, '//*[@id="shadow_host"]')
shadow_root1 = shadow_host.shadow_root
shadow_host1 = shadow_root1.find_element(By.XPATH, '/span')

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator

I know that I can use CSS Selectors, but I want to use it in case there aren't any CSS Selectors. Can you help me, how to write shadow_host1 correctly using XPATH? Thanks

2
  • '//span' (double slash)? Commented Feb 5, 2023 at 14:41
  • Does not work:( Thanks for the answer @Yevhen Kuzmovych Commented Feb 5, 2023 at 14:48

1 Answer 1

1

You cannot use XPATH locators with shadow root. You can use CSS LOCATORS instead (when on a Chrome/chromedriver setup), or alternatively (when using a Firefox/geckodriver setup) use javascript selectors (querySelector).

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

3 Comments

So how can I click on an option element? <csgofloat-page-size class="page-selector"> #shadow-root (open) <select> <option value="10"> "10" </option> </select> </csgofloat-page-size> Thank you very much for your answer
This is a different question. My answer addressed your original question. If you have more, post them as new questions.
@KraKoff_ -- just in case this answer is relevant to your follow-up question: stackoverflow.com/questions/73653766/…

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.