python - 如何在没有定义 ID 的情况下使用 selenium 登录网站?
问题描述
我尝试输入我的大学帐户以避免填写 7 个完全相同的调查,而我回答的内容并不重要。如果我不手动填写,我就无法注册我的科目,而且每个学期都一样。我尝试了以下代码试图从 中查找元素xpath
,但它得到了Unable to locate element: {"method": "xpath", "selector": "// input [@type = 'text' and @ name = 'p_codigo_c'] "} (Session info: chrome = 92.0.4515.107)
我怎样才能解决这个问题?
解决方案
用户名和密码字段位于框架内。在访问其中的元素之前切换到框架。像这样。
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()
推荐阅读
- javascript - DOM 元素(节点)
- php - 使用 laravel 从控制器返回更多值到视图的最佳方法是什么?
- python - 在Django中提交表单后如何使用对象ID重定向到新页面?
- javascript - 您如何在 Shopify 上将颜色的产品选项分为“必需品”和“限量版”两类?
- php - 登录页面重定向到laravel 6中的身份验证后的空白页面
- jquery - 如何在图像加载时更改元素的高度?
- java - 如何在 JavaFX 中的密码字段本身中屏蔽和取消屏蔽 JFXPasswordField 的字符
- mysql - 已解决触发器以检查预留 mysql 的可用性
- functional-programming - 如何重构两个相似的函数以减少 Elixir 中的代码重复?
- java - Android 10 使用包含点“.”的显示名称创建媒体存储条目 前线 EX:.nomedia