Search code examples
pythonselenium-webdriversafari

Using selenium WebDriver to perform a click in python


I have a button defined on a webpage as:

<div class="form-group mt-3 mb-1 d-grid">
    <button type="submit" class="btn btn-lg btn-primary">
            Login
    </button>
</div>

In Python, I have coded up like so...

browser = webdriver.Safari(options=Options)
browser.get(url)
browser.find_element("xpath","//*[contains(text(), 'Login')]").click()

I get the exception below...

in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: 

How do I automate the click on the login button?


Solution

  • from selenium.webdriver.common.keys import Keys
    
    browser = webdriver.Safari(options=Options)
    browser.get(url)
    login_btn = browser.find_element("xpath","//*[contains(text(), 'Login')]")
    
    login_btn.send_keys(Keys.ENTER)