Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 不一致的异常-在缓存中找不到元素-可能页面已在之后更改_Ruby_Selenium_Automation_Selenium Webdriver - Fatal编程技术网

Ruby 不一致的异常-在缓存中找不到元素-可能页面已在之后更改

Ruby 不一致的异常-在缓存中找不到元素-可能页面已在之后更改,ruby,selenium,automation,selenium-webdriver,Ruby,Selenium,Automation,Selenium Webdriver,我正在运行Selenium webdriver Ruby脚本,但不一致地遇到此错误:- [remote server] resource://fxdriver/modules/web_element_cache.js:7610:in `fxdriver.cache.getElementAt': Element not found in the cache - perhaps the page has changed since it was looked up (Selenium::WebDr

我正在运行Selenium webdriver Ruby脚本,但不一致地遇到此错误:-

[remote server] resource://fxdriver/modules/web_element_cache.js:7610:in `fxdriver.cache.getElementAt': Element not found in the cache - perhaps the page has changed since it was looked
 up (Selenium::WebDriver::Error::StaleElementReferenceError)
        from [remote server] file:///C:/Users/AKULKA~1/AppData/Local/Temp/webdriver-profile20140510-2952-10nsq50/extensions/fxdriver@googlecode.com/components/command_processor.js:7210:
in `Utils.getElementAt'
        from [remote server] file:///C:/Users/AKULKA~1/AppData/Local/Temp/webdriver-profile20140510-2952-10nsq50/extensions/fxdriver@googlecode.com/components/command_processor.js:8223:
in `fxdriver.preconditions.visible'
        from [remote server] file:///C:/Users/AKULKA~1/AppData/Local/Temp/webdriver-profile20140510-2952-10nsq50/extensions/fxdriver@googlecode.com/components/command_processor.js:10861
有时脚本运行成功,有时抛出此错误并失败。 我尝试添加等待等,但没有任何帮助

有什么不对劲吗

以下是脚本失败的代码:-

# Go to Maintenance tab
wait.until {browser.find_element(:xpath,"/html/body/div[5]/div/div/div/div/div/div[2]/div[2]/div/div/div/table/tbody/tr/td[2]/div/div/table/tbody/tr/td[6]/a")}
browser.find_element(:xpath,"/html/body/div[5]/div/div/div/div/div/div[2]/div[2]/div/div/div/table/tbody/tr/td[2]/div/div/table/tbody/tr/td[6]/a").click
不仅仅是这一行代码,有时脚本在另一行失败,引发相同的异常,有时一切都很完美。 为什么会有这样的不一致

先谢谢你。
Abhishek

在搜索之前将源代码写入文件。在脚本失败和成功时获取源代码的副本。然后在这两个文件上运行diff。看看您的xpath,很明显您的解决方案非常脆弱。@7stud在搜索之前将源代码写入一个文件,我应该怎么做?此外,当脚本失败或成功时,脚本中没有任何更改。它一直都是一样的。你能提供一些关于你的脚本正在做什么的上下文吗?在尝试单击“维护”选项卡之前,您在做什么?脚本尝试单击模块中的不同JavaScript选项卡。有时,选项卡单击成功,有时不继续抛出缓存中未找到的元素错误。