Issue
I have a button
<input type="submit" class="button button_main" style="margin-left: 1.5rem;" value="something">
I cannot find it by id or name and need to submit a form.
I tried doing this: Alternatively, WebDriver has the convenience method “submit” on every element. If you call this on an element within a form, WebDriver will walk up the DOM until it finds the enclosing form and then calls submit on that. If the element isn’t in a form, then the NoSuchElementException will be raised: element.submit() http://selenium-python.readthedocs.org/navigating.html
But that cannot find the submit selector either.
ideas?
Solution
There are many options here, to name a few:
If class alone is unique, you can use
driver.find_element_by_css_selector(".button_main").click()
If class + value combo is unique, you can use:
driver.find_element_by_css_selector(".button_main[value='something']").click()
You can also use xpath:
driver.find_element_by_xpath("//input[@type='submit' and @value='something']").click()
If none of those work (i.e. they are not identifying button uniquely), look at the elements above the button (for example <form
) and provide the xpath in format:
driver.find_element_by_xpath("//unique_parent//input[@type="submit" and @value='something']").click()
Answered By - timbre timbre
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.