stevepryde / thirtyfour

Selenium WebDriver client for Rust, for automated testing of websites
Other
985 stars 68 forks source link

Sematics around query from element #155

Open bcpeinhardt opened 1 year ago

bcpeinhardt commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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