我尝试输入我的大学帐户以避免填写 7 份完全相同的调查,无论我回答什么都无所谓。如果我不手动填写,我就无法注册我的科目,每个学期都一样。我尝试了以下代码,试图从 中查找元素xpath
,但它得到Unable to locate element: {"method": "xpath", "selector": "// input [@type = 'text' and @ name = 'p_codigo_c'] "} (Session info: chrome = 92.0.4515.107)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
USERNAME = xxxxxxx
PASSWORD = xxxxxx
driver = webdriver.Chrome('C:\Dev\chromedriver.exe')
wait = WebDriverWait(driver, 20)
driver.get('http://siiauescolar.siiau.udg.mx/')
user_input = driver.find_element_by_xpath("//input[@type = 'text' and @name='p_codigo_c']")
user_input.send_keys(USERNAME)
password_input = driver.find_element_by_xpath("//input[@type = 'password' and @name='p_clave_c']")
password_input.send_keys(PASSWORD)
login_button = driver.find_element_by_xpath("//input[@type = 'submit' and @value='Ingresar']")
login_button.click()
我怎样才能解决这个问题?
用户名和密码字段位于框架内。在访问其中的元素之前切换到框架。像这样。
driver.switch_to_frame(driver.find_element_by_xpath("//frame[@name='mainFrame']"))
user_input = driver.find_element_by_xpath("//input[@type = 'text' and @name='p_codigo_c']")
user_input.send_keys(USERNAME)
password_input = driver.find_element_by_xpath("//input[@type = 'password' and @name='p_clave_c']")
password_input.send_keys(PASSWORD)
login_button = driver.find_element_by_xpath("//input[@type = 'submit' and @value='Ingresar']")
login_button.click()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句