目前我正在编写webdrivertestforsearch,它使用ajax提供建议。如果在键入搜索内容后按enter之前添加显式wait,那么Test工作得很好。
wd.find_element_by_xpath("//div[@class='searchbox']/input").send_keys("obama")
time.sleep(2)
wd.find_element_by_xpath("//div[@class='searchbox']/input").send_keys(Keys.RETURN)
但是
wd.find_element_by_xpath("//div[@class='searchbox']/input").send_keys("obama")
wd.find_element_by_xpath("//div[@class='searchbox']/input").send_keys(Keys.RETURN)
失败了。我用一个虚拟cpu在ec2上运行测试。我怀疑,甚至在发送与搜索相关的GET请求之前就按了enter,如果在建议之前按了enter,则失败。
有没有更好的方法来添加显式等待?
那又怎么样:
例如:
在这种情况下,每次单击或查找元素时,驱动程序将在10秒内每隔0.5秒尝试执行此操作。在这种情况下,不需要每次都添加wait。 注意:但这只是关于屏幕上的元素。它不会等到某些JS操作结束。
添加这个方法,在这里我确保API响应从服务器返回
您确实可以添加一个显式的等待元素的出现,如
见:http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits
相关问题 更多 >
编程相关推荐