当我的测试脚本执行以下命令时,我总是从 MacOS Sierra 上的 Safari Web 驱动程序获得响应状态 404(完整源代码见附件):
elemSubmit = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "submit")))
重现步骤: 1. 更新到 MacOS Sierra 和 Safari 10 2. 安装 python 3.6 3. 安装 Python 绑定:pip3.6 install -U selenium 4. 运行附加的测试脚本:python3.6 test.py
预期结果:测试脚本应该通过
实际结果:它总是失败,我写了一些日志,它显示:
driver_command: isElementDisplayed
params {'id': 'node-64681E7D-D268-429A-9C6F-9908A5D09250', 'sessionId': '7FE8FE61-805E-4B68-9EF5-2C7EA934A382'}
ERROR {'status': 404, 'value': ''}
版本:MacOS Sierra,Python 3.6
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
import time
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Safari(1234, '/usr/bin/safaridriver')
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, "q")))
# elem = WebDriverWait(self.driver, 1).until(EC.element_to_be_clickable((By.NAME, "q")))
# elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elemSubmit = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "submit")))
elemSubmit.click()
assert "No results found." not in driver.page_source
time.sleep(3)
# def tearDown(self):
# self.driver.close()
if __name__ == "__main__":
unittest.main()