Skip to content
Advertisement

Selenium (python) locating button relative to another div with Id

I need to click on the Ok button on a page (HTML code snippet hereunder). The button itself does not have an Id and its XPath changes. It can be any of the following:

JavaScript

The only stable locator I can find in the page is the noresultsfound Id of the div before the div that contains the button as a child div.

I am unable to guess which Selenium locator I could use to RELIABLY click on the button.

JavaScript

My code so far is like the following:

JavaScript

but as I said it fails on those pages where the XPath is different.

Is there a way of writing a locator anchored to the Id and find the button to click relative to that? Thanks

Advertisement

Answer

JavaScript

There are many selectors you could try for this element.

JavaScript
Advertisement