0

在Selenium测试中(使用版本2.40.0),我无法使用Internet Explorer 8远程查找包含链接文本的元素。它适用于Chrome。Selenium - IE 8 - 无法找到包含链接文本的元素

这里有一个公共网站(groovy)样本。

import org.junit.Test 
import org.openqa.selenium.By 
import org.openqa.selenium.remote.DesiredCapabilities 
import org.openqa.selenium.remote.RemoteWebDriver 

class SampleIT { 

    @Test 
    void test() { 
     def abilities = DesiredCapabilities.internetExplorer() 
     def webDriver = new RemoteWebDriver(new URL("http://10.50.26.116:4444/wd/hub"), abilities) 
     webDriver.get("http://www.seznam.cz") 
     webDriver.findElement(By.linkText("Firmy")).click() 
    } 

} 

这是登录

org.openqa.selenium.NoSuchElementException: Unable to find element with link text == Firmy (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 285 milliseconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:54:28' 
System info: host: 'ghana-selenium', ip: '10.50.26.116', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45' 
Session ID: 78d4e326-4916-4aee-9834-dafbc304a8ed 
Driver info: org.openqa.selenium.ie.InternetExplorerDriver 
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=8, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=http://localhost:44587/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}] 
Command duration or timeout: 424 milliseconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: '2.40.0', revision: '4c5c0568b004f67810ee41c459549aa4b09c651e', time: '2014-02-19 11:13:01' 
System info: host: 'ubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.11.0-18-generic', java.version: '1.7.0_40' 
Session ID: c542b45e-03d0-43dd-ba5f-c8748d732d85 
Driver info: org.openqa.selenium.remote.RemoteWebDriver 
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, webdriver.remote.sessionid=c542b45e-03d0-43dd-ba5f-c8748d732d85, version=8, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=http://localhost:44587/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193) 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:573) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:326) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:375) 
    at org.openqa.selenium.By$ByLinkText.findElement(By.java:242) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:318) 
    at org.openqa.selenium.WebDriver$findElement$0.call(Unknown Source) 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) 
    at SampleIT.test(SampleIT.groovy:13) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) 
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken 
Build info: version: '2.40.0', revision: '4c5c0568b004f67810ee41c459549aa4b09c651e', time: '2014-02-19 11:13:01' 
System info: host: 'ubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.11.0-18-generic', java.version: '1.7.0_40' 
Driver info: driver.version: RemoteWebDriver 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:125) 
    ... 36 more 
Caused by: org.openqa.selenium.NoSuchElementException: Unable to find element with link text == Firmy (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 285 milliseconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:54:28' 
System info: host: 'ghana-selenium', ip: '10.50.26.116', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45' 
Session ID: 78d4e326-4916-4aee-9834-dafbc304a8ed 
Driver info: org.openqa.selenium.ie.InternetExplorerDriver 
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=8, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=http://localhost:44587/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}] 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: '2.40.0', revision: '4c5c0568b004f67810ee41c459549aa4b09c651e', time: '2014-02-19 11:13:01' 
System info: host: 'ubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.11.0-18-generic', java.version: '1.7.0_40' 
Driver info: driver.version: EventFiringWebDriver 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193) 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:573) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:326) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:375) 
    at org.openqa.selenium.By$ByLinkText.findElement(By.java:242) 
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:318) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:101) 
    at com.sun.proxy.$Proxy2.findElement(Unknown Source) 
    at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:184) 
    at org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:47) 
    at org.openqa.selenium.remote.server.handler.FindElement.call(FindElement.java:1) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:170) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 


Process finished with exit code 255 

编辑 我想在家里和它的工作。但在办公室,问题持续存在。可能受IE影响的网络设置,Windows域等?

回答

2

我认为你的编辑可能是正确的。

Selenium Internet Explorer wiki,你可以看到以下所需配置:

  • 在IE 7或更高版本的Windows Vista或Windows 7,则必须为每个区是设置保护模式设置相同的价值。该值可以打开或关闭,只要每个区域的值相同即可。要设置保护模式设置,请从工具菜单中选择“Internet选项...”,然后单击安全选项卡。对于每个区域,在标签为“启用保护模式”的选项卡底部会出现一个复选框。 此外,对于IE 10及更高版本,必须禁用“增强保护模式”。该选项位于“Internet选项”对话框的“高级”选项卡中。

  • 必须将浏览器缩放级别设置为100%,以便可以将原生鼠标事件设置为正确的坐标。

  • 仅适用于IE 11,您需要在目标计算机上设置注册表项,以便驱动程序可以维护与其创建的Internet Explorer实例的连接。对于32位Windows安装,您必须在注册表编辑器中检查的密钥是HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BFCACHE。对于64位Windows安装,密钥为HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BFCACHE。请注意,FEATURE_BFCACHE子键可能存在也可能不存在,如果不存在则应该创建。重要提示:这里面的关键,创建0

我的猜测是,你的问题是与保护模式值名为iexplore.exe的DWORD值。

+0

这真的是一个棘手的! – banterCZ

1

硒等待链接在页面上只显示285毫秒。您可以尝试使用implicit or explicit等待,等待足够长的时间以确保页面加载后该元素是否存在。

并确保Firmy是您的锚标记中存在的确切单词,即使有额外的空间它也会抛出Nosuchelement异常。如果不确定,您可以使用PartialLinkText

这是使用显式的等待:

new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Firmy"))).click(); 

这将等待30秒的元素是可见的。

+0

链接就在那里,这就是为什么我提到公共网页。我认为,问题可能是IE版本或代理。我必须跟踪原因。 – banterCZ

相关问题