I want to verify that class has highlighted a table row background clicked.
This is my row: xpath=.//*[@id="my-row-0"]/td[3]/div[2]/div[1] This is the class that is either off (not clicked) contains(@class, 'my-graphic-link body-row not-selected')] or on contains(@class, 'my-graphic-link body-row is-selected')]
I’m using Wait until page contains element after row is click but just get errors.
It’s not clear if you mean that the TD element (//[@id=“my-row-0”]/td[3]) or the DIV element (//[@id=“my-row-0”]/td[3]/div[2]/div[1]) is the one that gets the changed class? I would expect in a web app the class to be applied to the TD elements, but I have seen developers do some pretty wacky things.
You also didn’t show your robot script so it’s a bit hard for us to know what you already have but one of these might work, i’m just guessing as there is not enough info to do anything else:
Wait until page contains element | //*[@id="my-row-0"]/td[3]/div[2]/div[contains(@class, "is-selected")] Wait until page contains element | //*[@id="my-row-0"]/td[contains(@class, "is-selected")]
But those will be true if any TD or DIV (depending on which you used) has the is-selected class.
Another way you could approach it would be to collect the class attribute from the required element and then test the contents of the class, e.g.
${class}= | Get Element Attribute //*[@id="my-row-0"]/td[3]/div[2]/div[1]
or ${class}= | Get Element Attribute //*[@id="my-row-0"]/td[3]
Followed by a simple Should Contain | ${class} | is-selected
Especially for the first selected item and if there is a delay between clicking a checkbox and the style being applied you might need to combine both methods, 1st wait for any element of the type your expecting to have the is-selected class, then test the specific element has the class.
Thanks for your help. I am using Selenium library and running the tests in RIDE. This is my error:
InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression .//*[@class="my-graphic-link body-row is-selected"]/td[3]/div[2]/div[1] contains(@class, 'my-graphic-link body-row is-selected')] because of the following error:
SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘.//*[@class=“my-graphic-link body-row is-selected”]/td[3]/div[2]/div[1] contains(@class, ‘my-graphic-link body-row is-selected’)]’ is not a valid XPath expression.
When the user presses the table row only at that point is `is-selected`` added to the class. So my logic was that after row click search page for that class to be visible which is:
Click Element //*[@id="my-row-0"]
Wait For Load Finish
Wait until page contains element xpath=.//*[@class="my-graphic-link body-row **is-selected**"]/td[3]/div[2]/div[1] contains(@class, 'my-graphic-link body-row **is-selected**')]
Are you able to show us a snippet of the html you are trying to use the xpath on before and after selecting the row? Then I might have a better idea why it’s not working for you.
can you add these 2 lines to your test case and show the result?:
${class}= | Get Element Attribute //tr[@id="my-row-0"]
Should Contain | ${class} | is-selected
I think that will work, from what you were describing earlier you were trying to check the is-selected on the td or div elements inside the tr, but it now looks like it’s the tr you needed to check
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//tr[(' is not a valid XPath expression.
Verify Highlightable Areas
Click Element //*[@id="my-row-0"]
${class}= Get Element Attribute //tr[@id="my-row-0"]
Page Should Contain ${class} is-selected
Are you sure that failure is on these lines? the reason I ask is the error message says ‘//tr[(’ is not valid xpath, which is true but none of these lines have the ‘(’ character, so it looks like that error is coming from somewhere else.