Friday, March 14, 2025

Selenium and Python – The way to click on submit button


Advocate not utilizing xpath, here’s a doc explaining selector speeds and reliability: right here

Utilizing css selector might be extra dependable and sooner, would additionally counsel altering to the under, which can (ought to) repair your subject and add some additional helpful bits.

from selenium import webdriver
from selenium.webdriver.frequent.keys import Keys
from selenium.webdriver.frequent.by import By
from selenium.webdriver.assist.ui import WebDriverWait
from selenium.webdriver.assist import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager

# Initialize the WebDriver occasion utilizing webdriver-manager
driver = webdriver.Chrome(ChromeDriverManager().set up())

# Navigate to the login web page
driver.get("https://eu.luxpowertek.com/WManage/net/login")

# Look ahead to the username subject to be current
wait = WebDriverWait(driver, 10)  # 10 seconds timeout
username_field = wait.till(EC.presence_of_element_located((By.ID, "account")))
username_field.send_keys("[email protected]")

# Look ahead to the password subject to be current and enter the password
password_field = wait.till(EC.presence_of_element_located((By.ID, "password")))
password_field.send_keys("kinghferyrt")

# Look ahead to the sign-in button to be clickable and click on it
sign_in_button = wait.till(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn-success")))
sign_in_button.click on()
  
# Lastly, shut the browser. You may need to take away this throughout growth.
driver.give up()

(I haven’t examined this, however will roughly be what you’re in search of – this additionally makes use of chrome driver supervisor which suggests you don’t must level to a neighborhood driver, it’ll obtain and cache it on the fly)

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com