Selenium IDE录制的百度搜索并点击结果测试用例回放报错

  • Post author:
  • Post category:其他


初学Selenium,用Selenium IDE录制了一个简单的用例:打开百度-输入搜索内容-并点击任意一个搜索结果

保存成python的脚本后执行,定位搜索结果元素那行代码一直报错

Error

Traceback (most recent call last):

File “D:\Python File\SeleniumTest\record.py”, line 26, in test_record

driver.find_element_by_link_text(“Query Error”).click()

File “D:\Program Files\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py”, line 72, in click

self._execute(Command.CLICK_ELEMENT)

File “D:\Program Files\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py”, line 461, in _execute

return self._parent.execute(command, params)

File “D:\Program Files\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 236, in execute

self.error_handler.check_response(response)

File “D:\Program Files\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 192, in check_response

raise exception_class(message, screen, stacktrace)

WebDriverException: Message: unknown error: Element is not clickable at point (162, 609). Other element would receive the click: <div id=”_mask” style=”opacity: 0.3; position: absolute; z-index: 300; top: 93px; left: 0px; width: 1015px; height: 1403px; background: rgb(255, 255, 255);”></div>

(Session info: chrome=50.0.2661.102)

(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 10.0.10240 x86_64)



解决办法:在前面加了个time.sleep(2) 就OK了

def test_record(self):
    driver = self.driver
    driver.get(self.base_url + "/")
    driver.find_element_by_id("kw").clear()
    driver.find_element_by_id("kw").send_keys("liuhy test")
    driver.find_element_by_id("su").click()
    driver.find_element_by_id("su").click()
    time.sleep(2)
    driver.find_element_by_link_text("Query Error").click()



版权声明:本文为LhyUp原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。