Help locating element

Hi,

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.

Any help appreciated.

What are the errors you are getting? Is this using SeleniumLibrary? A web app or something else?

Hi Brendan,

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.

Hopefully this helps,

Dave.

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**')]

Hi Brendan,

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.

Dave.

<tr class="my-graphic-link body-row is-selected" id="my-row-0">

The “is-selected” only shows when row clicked… so this is taken from a clicked state.

I need to be able to verify that the row is still in a “highlightable” state.

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

Hopefully this works,

Dave.

Thanks, I’m getting an error when running code:

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

Hi Brendan,

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.

Dave.

Hi Dave,

I ran the code with and without “( )” to see if it made a difference and got the same error.

Unfortunately you aren’t providing enough information for me to figure out what is going on, perhaps someone else will chime in and can help you?

Hi Dave,

I fixed this by using `Page Should Contain Element [(@class, ‘my-graphic-link body-row not-selected’)] and contains(@class, ‘is-selected’)]

Thank you for your help, much appreciated.

`

1 Like

Great! I’m glad you solved it :+1:t3: