Reputation: 45
I am trying to click on a button using selenium, and the only selector I can use is button's type. The problem is that there are two buttons with the same type on the webpage. And the problem is that I cannot control which one I am selecting. Currently, I am using:
```inputElement=fox.find_element_by_css_selector("button[type='submit']")```
However, this selects only the first button, not the second one. I think the solution would be to somehow identify button which lives inside a class which lives inside a different class. Is it possible to do something like that? I am documenting the problem below:
The first image is the one where the button is fetched with the line of code I gave, and the second one is the one where I cannot fetch the button.
Thanks!
Upvotes: 1
Views: 31
Reputation: 29362
if you are interest in the xpath then, you can do multiple things like indexing or giving just the text between button tag.
you can do something like this :
fox.find_element_by_xpath("(//button[@type='submit'])[2]")
or
fox.find_element_by_xpath("//button[@type='submit' and contains(text(), 'Ponisti')]")
for second button, just change this Ponisti
to the button text
there are still few more ways to differentiate buttons.
Upvotes: 1