The bug which can be found at
SeleniumHQ#13642 happened in the
table of the first example at
https://www.w3schools.com/html/html_tables.aspFor. The table has 7 rows
and 3 columns. I added the values of the first 3 rows below where each
line represents a row and the values of each row are separated by a
comma and a space. All cells are td elements apart from the cells of
the first row which are th elements. The table has "collapse" as the
value of the "border-collapse" CSS property.
Company, Contact, Country
Alfreds Futterkiste, Maria Anders, Germany
Centro comercial Moctezuma, Francisco Chang, Mexico
The person who raised the bug was trying, in Chrome and using relative
locators, to get the cell that was to the right of the cell containing
"Alfreds Futterkiste" and below the cell containing "Contact". They
asserted that the text of the cell they were getting was "Maria Anders"
but got "Germany" instead.
I created a browser test in Chrome called
shouldBeAbleToFindElementWithToRightOfAndBelowWithBorderCollapseInTable
reproducing the steps of the bug in the
java/test/org/openqa/selenium/support/locators/RelativeLocatorTest.java
Java class and got "Mexico".
I made all my modifications to the logic of the project inside the
javascript/atoms/locators/relative.js JavaScript file. I modified the
bot.locators.relative.below_ and the bot.locators.relative.rightOf_
functions and added a util function called
twoElementsAreCellsOfATableThatUsesBorderCollapse.
Before my modifications, inside the bot.locators.relative.below_
function, for the nested function we returned, we only considered that
B was below A if the top of B was below the bottom of A. In a table
that has collapsing borders, neighboring cells touch each other. For
the the bot.locators.relative.below_ function, I don't call the
bot.locators.relative.proximity_ function since I need access to the
elements, not just rect1 and rect2. I return a function in which I
consider that B is below A also if the top of B is at the same vertical
position as the bottom of A and if the two elements are cells of the
same table. To verify the first part (before the "and") of the
condition I added, I call a utility function I created called
twoElementsAreCellsOfATableThatUsesBorderCollapse which takes in the
two elements and returns true only if the condition described by its
name is true. I modified the documentation of the function
bot.locators.relative.below_. The old documentation had the two
elements switched. My new documentation does not contain that switch.
Before my modifications, inside the bot.locators.relative.rightOf_
function, for the nested function we returned, we only considered that
B was to the right of A if the left of B was to the right of the right
of A. For the the bot.locators.relative.rightOf_ function, I don't call
the bot.locators.relative.proximity_ function since I need access to
the elements, not just rect1 and rect2. I return a function in which I
consider that B is to the right of A also if the left of B is at the
same horizontal position as the right of A and if the two elements are
cells of the same table. To verify the first part (before the "and") of
the condition I added, I call again the
twoElementsAreCellsOfATableThatUsesBorderCollapse function.
As I was informed on the Slack application, the tests will be run after
I make my pull request. I only ran the test I created, which passed.
Fixes SeleniumHQ#13642
User description
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.
Description
I created a browser test in Chrome called shouldBeAbleToFindElementWithToRightOfAndBelowWithBorderCollapseInTable reproducing the steps of the bug in the java/test/org/openqa/selenium/support/locators/RelativeLocatorTest.java Java class and got "Mexico".
I made all my modifications to the logic of the project inside the javascript/atoms/locators/relative.js JavaScript file. I modified the bot.locators.relative.below_ and the bot.locators.relative.rightOf_ functions and added a util function called twoElementsAreCellsOfATableThatUsesBorderCollapse.
Before my modifications, inside the bot.locators.relative.below_ function, for the nested function we returned, we only considered that B was below A if the top of B was below the bottom of A. In a table that has collapsing borders, neighboring cells touch each other. For the the bot.locators.relative.below_ function, I don't call the bot.locators.relative.proximity_ function since I need access to the elements, not just rect1 and rect2. I return a function in which I consider that B is below A also if the top of B is at the same vertical position as the bottom of A and if the two elements are cells of the same table. To verify the first part (before the "and") of the condition I added, I call a utility function I created called twoElementsAreCellsOfATableThatUsesBorderCollapse which takes in the two elements and returns true only if the condition described by its name is true. I modified the documentation of the function bot.locators.relative.below_. The old documentation had the two elements switched. My new documentation does not contain that switch.
Before my modifications, inside the bot.locators.relative.rightOf_ function, for the nested function we returned, we only considered that B was to the right of A if the left of B was to the right of the right of A. For the the bot.locators.relative.rightOf_ function, I don't call the bot.locators.relative.proximity_ function since I need access to the elements, not just rect1 and rect2. I return a function in which I consider that B is to the right of A also if the left of B is at the same horizontal position as the right of A and if the two elements are cells of the same table. To verify the first part (before the "and") of the condition I added, I call again the twoElementsAreCellsOfATableThatUsesBorderCollapse function.
As I was informed on the Slack application, the tests will be run after I make my pull request. I only ran the test I created, which passed.
Motivation and Context
The bug which can be found at #13642 happened in the table of the first example at https://www.w3schools.com/html/html_tables.aspFor. The table has 7 rows and 3 columns. I added the values of the first 3 rows below where each line represents a row and the values of each row are separated by a comma and a space. All cells are td elements apart from the cells of the first row which are th elements. The table has "collapse" as the value of the "border-collapse" CSS property.
Company, Contact, Country
Alfreds Futterkiste, Maria Anders, Germany
Centro comercial Moctezuma, Francisco Chang, Mexico
The person who raised the bug was trying, in Chrome and using relative locators, to get the cell that was to the right of the cell containing "Alfreds Futterkiste" and below the cell containing "Contact". They asserted that the text of the cell they were getting was "Maria Anders" but got "Germany" instead.
Types of changes
Checklist
PR Type
Bug fix, Tests
Description
RelativeLocatorTest.javato verify the bug fix for relative locators in tables with border-collapse.below_function inrelative.jsto correctly identify elements below each other in tables with border-collapse.rightOf_function inrelative.jsto correctly identify elements to the right of each other in tables with border-collapse.twoElementsAreCellsOfSameTableto check if two elements are cells of the same table.Changes walkthrough 📝
RelativeLocatorTest.java
Add test case for verifying relative locators with border-collapsejava/test/org/openqa/selenium/support/locators/RelativeLocatorTest.java
with border-collapse.
relative.js
Fix relative locators for tables with border-collapsejavascript/atoms/locators/relative.js
below_function to handle elements in tables withborder-collapse.
rightOf_function to handle elements in tables withborder-collapse.
twoElementsAreCellsOfSameTableto check tablecell relationships.