Skip to content
Advertisement

Selenium 4.3.0 get the element of button type to python

I am struggling on how to get the button type element in this example, so that I can be able to test it using selenium in python.

<button class="login-button signin-button button-primary" type="submit"><div class="signin-text">Sign in</div></button>

My Code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service

import time


PATH = Service("C:Program Files (x86)chromedriver.exe")
driver = webdriver.Chrome(service=PATH)

driver.get("https://www.dropbox.com/login")


driver.find_element("name", "login_password").send_keys("123456")
driver.find_element("type", "submit").send_keys(Keys.ENTER)

time.sleep(5)
driver.close()


print("Test Completed Successfully ")

I think the code changed because of the selenium version? I need help guys Thank you.

Advertisement

Answer

There is no such selector type as "type". You can either use another locator for Submit button e.g.

driver.find_element("xpath", "//button[@type='submit']").send_keys(Keys.ENTER)

or this form submitting approach

input_field = driver.find_element("name", "login_password")
input_field.send_keys("123456")
input_field.submit()
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement