当前位置: 首页 > 知识库问答 >
问题:

Selenium:Internet Explorer中的NoSuchElementException

尉迟招
2023-03-14

我正在尝试将内部Webapp的Selenium脚本从Selenium IDE移植到使用Java中RemoteWebDrivers的Selenium网格设置。

这些脚本在Chrome和Firefox上运行良好,但在Internet Explorer上不行。每次尝试在页面中查找元素时,我只得到一个NoSuchElementException(页面本身加载很好)。

public class Wikipedia_test_IE {
 private WebDriver driver = null;
 private String baseUrl = null;
 private boolean acceptNextAlert = true;
 private StringBuffer verificationErrors = new StringBuffer();


 @Before
 public void setUp() throws Exception {
//      DesiredCapabilities cap = DesiredCapabilities.firefox();
 DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
 cap.setCapability(CapabilityType.VERSION, "9");

        driver = new RemoteWebDriver (new URL("http://192.168.1.230:4444/wd/hub"), cap);    
        baseUrl = "https://en.wikipedia.org/wiki/Rosetta_%28spacecraft%29";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 }

 @Test
 public void testAKTargobankTestfall1KN() throws Exception {
      driver.get(baseUrl);
      driver.findElement(By.linkText("space probe")).submit();
 }
}
server.cc(239) Command: POST /session {"desiredCapabilities":{"platform":"WINDOWS","ensureCleanSession":true,"browserName":"internet explorer","version":"9"}}
IESession.cpp(43) Mutex acquired for session initalization
IESession.cpp(105) Releasing session initialization mutex
command.cc(33) Raw JSON command: { "command" : "newSession", "locator" : { }, "parameters" : {"desiredCapabilities":{"platform":"WINDOWS","ensureCleanSession":true,"browserName":"internet explorer","version":"9"}} }
BrowserFactory.cpp(68) Ignoring Protected Mode Settings: 0
BrowserFactory.cpp(71) Checking validity of Protected Mode settings.
BrowserFactory.cpp(984) Detected IE version: 9, detected Windows version: 6
BrowserFactory.cpp(1074) Found Protected Mode setting value of 0 for zone 1
BrowserFactory.cpp(1074) Found Protected Mode setting value of 0 for zone 2
BrowserFactory.cpp(1074) Found Protected Mode setting value of 0 for zone 3
BrowserFactory.cpp(1074) Found Protected Mode setting value of 0 for zone 4
BrowserFactory.cpp(74) Has Valid Protected Mode Settings: 1
BrowserFactory.cpp(170) Starting IE using the IELaunchURL API
BrowserFactory.cpp(124) IE launched successfully with process ID 2188
BrowserFactory.cpp(130) Process with ID 2188 is executing iexplore.exe
BrowserFactory.cpp(313) Ignoring zoom setting: 0
BrowserFactory.cpp(581) Browser zoom level is 100%
IECommandExecutor.cpp(650) Persistent hovering set to: 1
ProxyManager.cpp(118) Using existing system proxy settings.
server.cc(308) Response: {"sessionId":"4aba017b-91e9-4f48-9f9f-f38b0464bb6b","status":303,"value":"/session/4aba017b-91e9-4f48-9f9f-f38b0464bb6b"}


server.cc(239) Command: GET /session/4aba017b-91e9-4f48-9f9f-f38b0464bb6b {}
command.cc(33) Raw JSON command: { "command" : "getSessionCapabilities", "locator" : { "sessionid" : "4aba017b-91e9-4f48-9f9f-f38b0464bb6b" }, "parameters" : {} }
IECommandExecutor.cpp(544) No alert handle is found
server.cc(308) Response: {"sessionId":"4aba017b-91e9-4f48-9f9f-f38b0464bb6b","status":0,"value":{"browserAttachTimeout":0,"browserName":"internet explorer","cssSelectorsEnabled":true,"elementScrollBehavior":0,"enableElementCacheCleanup":true,"enablePersistentHover":true,"handlesAlerts":true,"ie.browserCommandLineSwitches":"","ie.ensureCleanSession":false,"ie.forceCreateProcessApi":false,"ie.usePerProcessProxy":false,"ignoreProtectedModeSettings":false,"ignoreZoomSetting":false,"initialBrowserUrl":"http://localhost:15278/","javascriptEnabled":true,"nativeEvents":true,"platform":"WINDOWS","requireWindowFocus":false,"takesScreenshot":true,"unexpectedAlertBehaviour":"dismiss","version":"9"}}

server.cc(239) Command: POST /session/4aba017b-91e9-4f48-9f9f-f38b0464bb6b/timeouts/implicit_wait {"ms":30000}
command.cc(33) Raw JSON command: { "command" : "implicitlyWait", "locator" : { "sessionid" : "4aba017b-91e9-4f48-9f9f-f38b0464bb6b" }, "parameters" : {"ms":30000} }
IECommandExecutor.cpp(544) No alert handle is found
server.cc(308) Response: {"sessionId":"4aba017b-91e9-4f48-9f9f-f38b0464bb6b","status":0,"value":null}

server.cc(239) Command: POST /session/4aba017b-91e9-4f48-9f9f-f38b0464bb6b/url {"url":"https://en.wikipedia.org/wiki/Rosetta_%28spacecraft%29"}
command.cc(33) Raw JSON command: { "command" : "get", "locator" : { "sessionid" : "4aba017b-91e9-4f48-9f9f-f38b0464bb6b" }, "parameters" : {"url":"https://en.wikipedia.org/wiki/Rosetta_%28spacecraft%29"} }
IECommandExecutor.cpp(544) No alert handle is found
Browser.cpp(421) Navigate Events Completed.
Browser.cpp(452) Browser ReadyState is not '4', indicating 'Complete'; it was 1
Browser.cpp(421) Navigate Events Completed.
Browser.cpp(437) Browser busy property is true.

(最后两行重复几次)

ElementRepository.cpp(107) Refreshing managed element cache. Found 0 to remove from cache.
Browser.cpp(421) Navigate Events Completed.
Browser.cpp(476) Waiting for document to complete...
Browser.cpp(481) Not in navigating state
server.cc(308) Response: {"sessionId":"4aba017b-91e9-4f48-9f9f-f38b0464bb6b","status":0,"value":null}

server.cc(239) Command: POST /session/4aba017b-91e9-4f48-9f9f-f38b0464bb6b/element {"using":"link text","value":"space probe"}
command.cc(33) Raw JSON command: { "command" : "findElement", "locator" : { "sessionid" : "4aba017b-91e9-4f48-9f9f-f38b0464bb6b" }, "parameters" : {"using":"link text","value":"space probe"} }
IECommandExecutor.cpp(544) No alert handle is found
ElementFinder.cpp(49) Using FindElement atom to locate element having linkText = space probe
Browser.cpp(114) No child frame focus. Focus is on top-level frame
Script.cpp(485) -2147024891 [Zugriff verweigert]: Unable to execute code, call to IHTMLWindow2::execScript failed
Script.cpp(171) Cannot create anonymous function
ElementFinder.cpp(84) Unexpected error attempting to find element by mechanism linkText with criteria space probe

有什么想法吗?

共有1个答案

燕志学
2023-03-14

谢谢你的帮助。为了回答上面提到的一些问题,我应该在最初的帖子中包括这些问题:

-是的,它确实是IE 9-我已经在所有安全区域将保护模式设置为“启用”-使用单击而不是提交并没有什么区别(最初)

恰好运行Selenium节点的VM在夜间应用了安全更新,其中包括一个用于IE的安全更新。

所以,现在一切都正常了,我也不知道为什么。再次感谢!

 类似资料:
  • 我试图在IE11中执行SeleniumWebDriver java代码,即使在页面完全加载之后,它也会抛出“NoTouchElementException”。 Web驱动程序:IEDriverServer_Win32_2.53。0 IE版本:11 selenium:selenium-server-standalone-2.53。0.jar java:jdk1。八, 该应用程序由LoginPage和

  • 我正在尝试向inputbox提供输入。我也尝试过使用find\u by\u d/name和xpath。但是仍然得到 文件"C:\用户\1024983\AppData\本地\程序\Python\Python\Python37\lib\site-包\selenium\webDrive\远程\webdriver.py",第978行,find_element'value': value})['value'

  • 我使用子JPanel构造JScrollPane,然后尝试将JScrollPane添加到父JPanel中,希望有一个可滚动的自定义JPanel。 我有一个大的细白线前面的所有我的组件,他们是没有滚动。有什么想法吗?

  • 我已经为android Studio创建了一个webview应用程序。但没有加载web URL。错误为NET::ERR_ACCESS_DENIED。有谁能帮忙吗

  • 我有一个使用Java Version8的Spring和Maven的项目。当我运行maven update时,它适用于Java9或更高版本,当我编译它时,它适用于Java8。我注意到了这一点,因为用Maven更新会将一个特定的类更改为Java9,而我无法导入这个类。 这个类是:javax.annotation.generated(Java8)。 这是要导入的类。但是,当我进行maven更新时,文件的

  • 当应用程序启动EncryptionBootstrapConfiguration无法自动装配我的自定义TextEncryptor-https://github.com/spring-cloud/spring-cloud-commons/blob/cde7c7f3118382490c28776f66e0a56f248141fd/spring-cloud-context/src/main/java/or