-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Allow RelativeBy to start with any locator, not just tag name #9273
Allow RelativeBy to start with any locator, not just tag name #9273
Conversation
… tests for these methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thank you for the PR! I love the idea behind it, and it's going to be really helpful, but I think we should consider just passing in a general locator (a By
subclass) to be even more useful. What do you think? That'd mean replacing withTagName(String)
with with(By)
|
||
WebElement lowest = driver.findElement(By.id("below")); | ||
|
||
List<WebElement> elements = driver.findElements(withXpath("//p").above(lowest)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The xpath locators rooted with //
will (because of how xpath works) scan the entire document. My expectation with this is that we'll end up returning the first p
tag in the entire doc. I'm surprised this works as expected....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I use this xpath //p[position()=1]?
public void shouldBeAbleToCombineFiltersWithXpath() { | ||
driver.get(appServer.whereIs("relative_locators.html")); | ||
|
||
List<WebElement> seen = driver.findElements(withXpath("//td").above(By.id("center")).toRightOf(By.id("second"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this should be returning the very first td
in the document.
@@ -97,6 +99,16 @@ public static RelativeBy withTagName(String tagName) { | |||
return new RelativeBy(By.tagName(tagName)); | |||
} | |||
|
|||
public static RelativeBy withXpath(String xpathExpression) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be better to just allow someone to pass in an arbitrary locator at this point. That is, replace withTagName(String)
with with(By)
so folks can write with(tagName("td"))
or whatever takes their fancy.
please take a look @shs96c |
SonarCloud Quality Gate failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! This looks great. Thank you for working on it :) There's a couple of things that we can clean up, but it won't take long to do that, and I'll make the changes once this is landed.
java/client/src/org/openqa/selenium/support/locators/RelativeLocator.java
Show resolved
Hide resolved
LGTM, and I think this will make using the relative locators a lot nicer. Thank you! |
… tests for these methods
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
added new methods for RelativeBy(withXpath,withCssSelector)
Description
Added new Methods for RelativeLocator to improve UX.
Motivation and Context
I believe it improves UX. now it's easier to use RelativeLocator.
Types of changes
Checklist