Safari浏览器遇到硒问题

时间:2020-06-21 02:18:14

标签: selenium selenium-webdriver safari

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>

0 个答案:

没有答案