selenium - Safari 浏览器与 Selenium 有问题
问题描述
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
driver = webdriver.Safari()
driver.get("https://www.instagram.com/")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']"))).send_keys("username")
driver.find_element_by_xpath("//input[@name='password']").send_keys("password")
driver.find_element_by_xpath("//button/div[text()='Log In']").click()
运行上面的代码,希望它最终能工作并填写 instagram 登录页面。但是,它返回此错误...
---------------------------------------------------------------------------
TimeoutException Traceback (most recent call last)
<ipython-input-1-d0556cce8de8> in <module>
6 driver = webdriver.Safari()
7 driver.get("https://www.instagram.com/")
----> 8 WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']"))).send_keys("username")
9 driver.find_element_by_xpath("//input[@name='password']").send_keys("password")
10 driver.find_element_by_xpath("//button/div[text()='Log In']").click()
/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/support/wait.py in until(self, method, message)
78 if time.time() > end_time:
79 break
---> 80 raise TimeoutException(message, screen, stacktrace)
81
82 def until_not(self, method, message=''):
TimeoutException: Message:
在 Chrome 上也试过这个,但我仍然收到同样的消息。关于发生了什么的任何线索?下面是用户名块的 HTML。
<label class="f0n8F "><span class="_9nyy2">Phone number, username, or email</span><input aria-label="Phone number, username, or email" aria-required="true" autocapitalize="off" autocorrect="off" maxlength="75" name="username" type="text" class="_2hvTZ pexuQ zyHYP" value=""></label>
下面是密码块的 HTML。
<label class="f0n8F "><span class="_9nyy2">Password</span><input aria-label="Password" aria-required="true" autocapitalize="off" autocorrect="off" name="password" type="password" class="_2hvTZ pexuQ zyHYP" value=""></label>
解决方案
推荐阅读
- javascript - 贝宝和 ASP.Net | 深度神经网络 | 从服务器发出传递|设置值
- sql-server - 在没有公共键的情况下加入多个表
- javascript - 仅在主页上的 CSS
- typescript - 有什么好的方法可以调试 vuejs 计算的属性和模板吗?
- azure-devops - 是否有任何选项可以在 azure devops 服务中合并两个不同的组织?
- machine-learning - 训练分类算法所花费的时间
- angular - crossfilter2__WEBPACK_IMPORTED_MODULE_3__ 不是函数
- node.js - NestJS(Node)项目通过NEST CLI创建新项目时出错
- objective-c - 将 Swift 转换为 Objective C
- scala - java.lang.ClassCast errors.GenericRowWithSchema 不能转换为 scala.collection.Seq