How to locate an element in case id and class names are dynamically changing?

I see the other attributes are having unique value to locate the element than id or css? How can I use other attributes as a locator in seleniumLibrary?

Hi Yash,

First refer to the selenium documentation for Locating elements

If you have an element like this:

<button aria-label="open" onclick="function()">CLICK</button>

Then you might be able to simply:

    Click Button    aria-label:open

Likewise you could use xpath to be a bit more specific e.g.

<!DOCTYPE html>
<html>
<head>
</head>
<body>
	<center>
		<h1 style="color:green">GeeksforGeeks</h1>
		<button value="open">open</button>

		<button aria-label="opens a new window"
				value="open"> open </button>
	</center>
</body>
</html>

Clicking the second button with xpath:

    Click Button    xpath://center/button[@aria-label="opens a new window"]

Hope that helps,

Dave.

Hi Dave,

Thank you for your response. I already used the provided format to locate the element. However it gives error as not found. I have attched the image to this response to give better idea on the interface to explain the issue.

Hi Yash,

I suspect you can’t use a forward slash in the value for that type of selector, in this situation xpath is probably your best bet:

    Click Element    //*[@data-foundation-collection-item-id="/content/abc-university/test-homepage"]

Dave.