Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sematics around query from element #155

Open
bcpeinhardt opened this issue Jan 13, 2023 · 2 comments
Open

Sematics around query from element #155

bcpeinhardt opened this issue Jan 13, 2023 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@bcpeinhardt
Copy link
Contributor

It seems like when querying from a base element, some locators will query first from the element (By::Name and By::ClassName seem to do this as expected), whereas others will query from the top of the document like calling query from driver (By::Id and By::XPath seem to do this).

  1. Is this a library decision or a selenium decision?
  2. What do you think is the right behavior here? I know in valid HTML an ID should be unique, but it feels weird to query from an element reference and get a parent element as a result. Especially when another query like By::ClassName would return an element "under" the element being queried from before another with the same class further up the page.

If this doesn't make any sense I can put together an example later to demonstrate what I'm talking about.

@stevepryde
Copy link
Collaborator

This is a known issue with xpath and is a selenium / Webdriver thing. To search below the parent element with xpath you have to start with . /.

I wasn't aware of By::Id behaving this way. That seems surprising. There are a few selectors (name and classname for example) that are just convenient wrappers around the css selector. The rest are passed directly to webdriver.

It would be good to compare the behaviour with either the Java or python selenium client. If there is any difference then we should fix our side.

@stevepryde
Copy link
Collaborator

And it probably needs some clarifying docs in any case. The xpath one in particular is a huge gotcha.

@stevepryde stevepryde added the documentation Improvements or additions to documentation label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants