Reputation: 1515
I have a button displayed on the browser with the following tag which doesn't have ID or a single CSS class name. How can I find the Webelement and add a click to this button.
<button aria-describedby="notes" aria-label="Notes" autofocus="" class="btn btn-primary" role="dialog" type="button">OK</button>
Upvotes: 0
Views: 843
Reputation: 33361
Web elements can be located by XPath or CSS Selectors based on any unique combination of any attribute values or / and tag names and also based on their parent or child elements.
Since you didn't share the entire HTML of that page we can only guess about the correct unique locator for that element.
With XPath it can be something like:
"//button[text()='OK']"
Or
"//button[@aria-label='Notes']"
In CSS Selector style it will be
"button[aria-label='Notes']"
Upvotes: 2
Reputation: 82
Consider locating the Element by Tag Name. Go to the parent element which has a id or class name and get subelements by tag name (parentelement.find_element_by_tag_name('button')
) which is your button
Besides that, the button in your example has two classes.
You click on a button via the .click()
command.
Upvotes: 0