I am attempting to click a button on a html page using Python and selenium web driver.
This is the source code of the page http://pastebin.com/112g1Gje.
EDIT: The relevant part at is at the end.. "btn btn-primary"
I am really close to figuring this out: The class name had spaces in it and I replaced the spaces with the dots... that made it work (Thanks to another SO post).
driver.find_element_by_css_selector(".btn.btn-primary").click()
Now the error I get is:
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
So I am trying something like:
driver.execute_script('document.querySelector("btn.btn-primary").click()')
From my understanding I have to write a javascript that clicks the button instead because the element is not visible. But that doesn't work.
The error I get is almost unreadable:
driver.execute_script('document.querySelector("btn.btn-primary").click()')
File "/Users/Richie/anaconda/lib/python3.5/site- packages/selenium/webdriver/remote/webdriver.py", line 461, in execute_script
{'script': script, 'args':converted_args})['value']
File "/Users/Richie/anaconda/lib/python3.5/site- packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "/Users/Richie/anaconda/lib/python3.5/site- packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: document.querySelector(...) is null
Anyone know?
driver.find_element_by_css_selector(".btn.btn-lg.btn-block.btn-message.open-write-message").click()
I was clicking the wrong thing. Make sure to include the dots.