无法在 python 中的 selenium 中找到元素
unable to locate element in selenium in python
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
# Initiate the browser
browser = webdriver.Chrome(ChromeDriverManager().install())
# Open the Website
browser.get("https://lpsc.codetantra.com/login.jsp")
codetantra_name="JE7-202@lpsc-ab.com"
codetantra_password="AB0707"
browser.find_element_by_name("loginId").send_keys(codetantra_name)
browser.find_element_by_name("password").send_keys(codetantra_password)
browser.find_element_by_class_name("pull-right").click()
browser.find_element_by_xpath("//*[@id='homeCenterDiv']/div/div[1]/div/div[2]/a").click()
您在定位元素之前缺少等待条件/延迟。
添加:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "loginId"))).click()
之后就可以正常填写密码并点击登录按钮了
您需要引入 webdriverwait 才能完成这项工作。您要单击的元素是一个文本节点。虽然它不是普通文本。
查看以下代码:
代码:
driver = webdriver.Chrome("C:\Users\Inc\Desktop\Selenium+Python\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get('https://lpsc.codetantra.com/login.jsp')
codetantra_name="JE7-202@lpsc-ab.com"
codetantra_password="AB0707"
driver.find_element_by_name("loginId").send_keys(codetantra_name)
driver.find_element_by_name("password").send_keys(codetantra_password)
driver.find_element_by_id("loginBtn").click()
button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[role='button'][title='Click here to view Meetings']")))
button.click()
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
# Initiate the browser
browser = webdriver.Chrome(ChromeDriverManager().install())
# Open the Website
browser.get("https://lpsc.codetantra.com/login.jsp")
codetantra_name="JE7-202@lpsc-ab.com"
codetantra_password="AB0707"
browser.find_element_by_name("loginId").send_keys(codetantra_name)
browser.find_element_by_name("password").send_keys(codetantra_password)
browser.find_element_by_class_name("pull-right").click()
browser.find_element_by_xpath("//*[@id='homeCenterDiv']/div/div[1]/div/div[2]/a").click()
您在定位元素之前缺少等待条件/延迟。
添加:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "loginId"))).click()
之后就可以正常填写密码并点击登录按钮了
您需要引入 webdriverwait 才能完成这项工作。您要单击的元素是一个文本节点。虽然它不是普通文本。 查看以下代码:
代码:
driver = webdriver.Chrome("C:\Users\Inc\Desktop\Selenium+Python\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get('https://lpsc.codetantra.com/login.jsp')
codetantra_name="JE7-202@lpsc-ab.com"
codetantra_password="AB0707"
driver.find_element_by_name("loginId").send_keys(codetantra_name)
driver.find_element_by_name("password").send_keys(codetantra_password)
driver.find_element_by_id("loginBtn").click()
button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[role='button'][title='Click here to view Meetings']")))
button.click()