HTML元素是:
<html>
< div class="view view-text" style="text-decoration: none; top: 9px; width: 216px; font-family: Kiro-webfont,Helvetica Neue,Arial; font-size: 20px; font-weight: bold; text-align: center; color: rgb(255, 255, 255);">OK< / div>
<\html>
来自萤火虫的X-Path:
/html/body/div[3]/div/div/div[3]/div/div[3]/div/div[4]/div[2]/div/div/div[1]/div
没有额外的框架。 窗口正在我的代码中处理。 我正在使用x-path并且无法找到包含以下错误消息的元素。
16:45:32.443 INFO - 正在执行:[find element:By.xpath:/ html / body / div [3] / div / div / div [3] / div / div [3] / div / div [ 4] / DIV [2] / DIV / DIV / DIV [1] / DIV]) 16:45:38.258警告 - 抛出异常 org.openqa.selenium.NoSuchElementException:没有这样的元素:无法找到元素:{&#34;方法&#34;:&#34; xpath&#34;,&#34;选择器&#34;:&#34; / HTML /体/格[3] / DIV / DIV / DIV [3] / DIV / DIV [3] / DIV / DIV [4] / DIV [2] / DIV / DIV /格 [1] / DIV&#34;} (会话信息:chrome = 54.0.2840.71) (驱动程序信息:chromedriver = 2.25.426923(0390b88869384d6eb0d5d09729679f934aab9eed),platform = Windows NT 6.1.7601 SP1 x86_64)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:5.03秒 有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:&#39; 2.53.0&#39;,修订版:&#39; 35ae25b&#39;,时间:&#39; 2016-03-15 17:00:58&#39; 系统信息:主持人:&#39; CTV-RLEE&#39;,ip:&#39; 10.1.58.129&#39;,os.name:&#39; Windows 7&#39;,os.arch:&# 39; x86&#39;,os.version:&#39; 6.1&#39;,java.version:&#39; 1.8.0_111&#39; 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 功能[{applicationCacheEnabled = false,rotate = false,mobileEmulationEnabled = false,networkConnectionEnabled = false,chrome = {chromedriverVersion = 2.25.426923(0390b88869384d6eb0d5d097) 29679f934aab9eed),userDataDir = C:\ Users \ sarshad \ AppData \ Local \ Temp \ scoped_dir6280_29240},takesHeapSnapshot = true,pageLoadStrategy = normal,databaseEnabled = false,handlesAlerts = true,hasTouch Screen = false,version = 54.0.2840.71,platform = XP,browserConnectionEnabled = false,nativeEvents = true,acceptSslCerts = true,locationContextEnabled = true,webStorageEnabled = true,browserName = chro 我,takeScreenshot = true,javascriptEnabled = true,cssSelectorsEnabled = true}] 会话ID:fbbb0002ff27c39a173c81cca75088cc *元素信息:{Using = xpath,value = / html / body / div [3] / div / div / div [3] / div / div [3] / div / div [4] / div [2 ] / DIV / DIV / DIV [1] /格} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) 在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) 在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) 在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) 在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363) 在org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:500) 在org.openqa.selenium.By $ ByXPath.findElement(By.java:361) 在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) 在org.openqa.selenium.support.events.EventFiringWebDriver $ 2.invoke(EventFiringWebDriver.java:103) 在com.sun.proxy。$ Proxy1.findElement(未知来源) 在org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:188) 在org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:48) 在org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:1) at java.util.concurrent.FutureTask.run(Unknown Source) 在org.openqa.selenium.remote.server.DefaultSession $ 1.run(DefaultSession.java:176) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source) 在java.lang.Thread.run(未知来源) 16:45:38.263警告 - 例外:没有这样的元素:无法找到元素:{&#34;方法&#34;:&#34; xpath&#34;,&#34;选择器&#34;:&#34; / HTML /体/格[3] / DIV / DIV / DIV [3] / DIV / DIV [3] / DIV / DIV [4] / DIV [2] / DIV / DIV / DIV [1] / DIV&#34 ;} (会话信息:chrome = 54.0.2840.71) (驱动程序信息:chromedriver = 2.25.426923(0390b88869384d6eb0d5d09729679f934aab9eed),platform = Windows NT 6.1.7601 SP1 x86_64)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:5.03秒 有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:&#39; 2.53.0&#39;,修订版:&#39; 35ae25b&#39;,时间:&#39; 2016-03-15 17:00:58&#39; 系统信息:主持人:&#39; CTV-RLEE&#39;,ip:&#39; 10.1.58.129&#39;,os.name:&#39; Windows 7&#39;,os.arch:&# 39; x86&#39;,os.version:&#39; 6.1&#39;,java.version:&#39; 1.8.0_111&#39; 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 功能[{applicationCacheEnabled = false,rotate = false,mobileEmulationEnabled = false,networkConnectionEnabled = false,chrome = {chromedriverVersion = 2.25.426923(0390b88869384d6eb0d5d097) 29679f934aab9eed),userDataDir = C:\ Users \ sarshad \ AppData \ Local \ Temp \ scoped_dir6280_29240},takesHeapSnapshot = true,pageLoadStrategy = normal,databaseEnabled = false,handlesAlerts = true,hasTouch Screen = false,version = 54.0.2840.71,platform = XP,browserConnectionEnabled = false,nativeEvents = true,acceptSslCerts = true,locationContextEnabled = true,webStorageEnabled = true,browserName = chro 我,takeScreenshot = true,javascriptEnabled = true,cssSelectorsEnabled = true}] 会话ID:fbbb0002ff27c39a173c81cca75088cc * 元素信息:{Using = xpath,value = / html / body / div [3] / div / div / div [3] / div / div [3] / div / div [4] / div [ 2] / DIV / DIV / DIV [1] / DIV}
答案 0 :(得分:1)
您应该尝试使用new WebDriverWait(driver,10).until(ExpectedConditions.ElementToBeClickable(".//div[text()='OK']"))).click();
等待此窗口对话框按钮可见,并启用以下命令: -
${basedir}/.sonar