python - 无法访问表单域
问题描述
我正在尝试使用我的凭据登录此页面:https ://myibd.investors.com/secure/signin.aspx
当我“检查”它时 - 我可以看到类的形式gigya-login-form
但是当我“查看源代码”时,这种形式不存在。我假设表单是通过 JS(或类似的东西)加载的。我研究了 SO,但没有一个解决方案有帮助。主要是人们建议等待页面加载
等待元素加载 30 秒的代码
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
url = 'https://myibd.investors.com/secure/signin.aspx'
driver = webdriver.Chrome()
driver.get(url)
myElem = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CLASS_NAME, 'gigya-input-text')))
返回TimeoutException: Message: - 这意味着该元素永远不会加载。
有人可以帮我填写该表格并单击提交吗?谢谢!
UPD。我也尝试进入 iframe 内部,但效果不佳 :( 下面的代码
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it("signin-iframe"))
username = driver.find_element_by_name("username")
username.send_keys("my_user_name")
它抛出 ElementNotVisibleException: Message: element not visible (我尝试按照 SO 的想法使其可见,但没有运气)
解决方案
表单位于 iframe 内,因此为了能够处理输入字段,您需要切换到该 iframe:
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it("signin-iframe"))
username = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//input[@aria-label="Email" and @placeholder="Email *"]')))
username.send_keys("my_user_name")
password = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//input[@aria-label="Password" and @placeholder="Password *"]')))
password.send_keys("my_password")
username.submit()
推荐阅读
- console-application - Nlog 不是归档所有文件吗?
- .htaccess - HTACCESS 文件中的 WWW 重定向
- ios - 通过 URL 共享图像
- jboss - 如何将 jBoss Drools 与 Wso2 Micro Integrator 集成以将 Drools 用作业务规则管理系统
- php - PHP动态压延机
- java - Maven 和 Spring Boot:如何构建缩小尺寸的扁平 jar(使用 proguard 或类似工具)
- macos - 如何在 MacOS 中轻松重新分发 dylib?
- php - 服务器更新后重音作为问号
- amazon-web-services - Terraform 和 AWS:修改现有策略
- ruby-on-rails - 为什么 Rails 控制台乘错?