当我的测试脚本执行以下命令时,我总是从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()