【求大神帮忙】webdrive测试定位的一个元素循环第二次时不能click
测试使用xpath定位一个Button按钮,循环第一次时能够定位并且单击,但是第二次时,出现错误,错误如下Traceback (most recent call last):
File "E:\python_test\test-1.py", line 68, in <module>
driver.find_element_by_xpath("html/body/div[..]/div/div/button").click()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 70, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 404, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 195, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 170, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///c:/users/admini~1/appdata/local/temp/tmp4yhwzc/extensions/fxdriver@googlecode.com/components/command-processor.js:9615)
at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/admini~1/appdata/local/temp/tmp4yhwzc/extensions/fxdriver@googlecode.com/components/command-processor.js:12265)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/admini~1/appdata/local/temp/tmp4yhwzc/extensions/fxdriver@googlecode.com/components/command-processor.js:12282)
at fxdriver.Timer.prototype.setTimeout/<.notify (file:///c:/users/admini~1/appdata/local/temp/tmp4yhwzc/extensions/fxdriver@googlecode.com/components/command-processor.js:603)
报的错误时元素当时不可见,建议加个等待判断当元素可以见再点击 joykao 发表于 2015-8-25 10:49
报的错误时元素当时不可见,建议加个等待判断当元素可以见再点击
设置隐性等待10S,没有用 1) 可以尝试用wait.Until(ExpectedConditions.ElementIsClickable(***)),如果还是有问题,那可能是xpath有问题,譬如不唯一或者跳出框的code是存在另一个frame里面,要多加几层,你可以装个chrome的XPath Helper来帮你检测你的element xpath;
2)要么就是用switchTo来切换window了;
你这是循环么?貌似我也遇到一样的问题。
第一个元素操作OK,第二个就停止了。定位的元素,个数是对的,不过打印出来都是一样的值
页:
[1]