-2

I am using Python script to open a web page, then a tab and then i want to click on a button. I am stuck on the last part. I am unable to click the find button. Here is the HTML code when i am using inspect in chrome.

Code Snippet

input value="Find" class="cuesButton" name="findButton" 
onclick="javascript:onFindSubmit()" type="button"

Here is the button i am trying to click:

button to click

I tried driver.find_element_by_name, element_by_id. It says method css selector doesnt have this element by name but it still fails.

Sunny Patel
  • 7,830
  • 2
  • 31
  • 46
  • sample code: `driver.find_element_by_xpath('//*[@id="btnSubmit"]').click() ` inspect the element and get the xpath first – Pygirl Jan 02 '20 at 17:12
  • Does this answer your question? [python selenium click on button](https://stackoverflow.com/questions/21350605/python-selenium-click-on-button) – Sunny Patel Jan 02 '20 at 17:17
  • Getting this error:selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="findButton"]"} – Himanshu Vaish Jan 02 '20 at 17:21

1 Answers1

0

2 things can be happening, 1 the page isn’t finished loading, to wait use WebDriverWait like so:

wait = WebDriverWait(driver, 10)

Or 2, the element is in an iframe , in this case you would need to switch to it like so:

driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))

You can switch using xpath, name, cssselector, and tag name

Noah
  • 154
  • 11
  • Tried both but still its not working. Here is the error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"Find"} (Session info: chrome=79.0.3945.88) – Himanshu Vaish Jan 02 '20 at 19:03
  • Did you replace the respected values, like tag_name(“iframe”) – Noah Jan 02 '20 at 19:25
  • yes.. i used both Find, findButton..both didnt work – Himanshu Vaish Jan 03 '20 at 10:59