gpt4 book ai didi

java - Selenium:Internet Explorer 中的 NoSuchElementException

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:33 26 4
gpt4 key购买 nike

我正在尝试将用于内部 Web 应用程序的 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();
}
}

我试过使用 findElement(By.Id) 和 findElement(By.cssSelector) - 没有效果。在页面加载和选择之间放置延迟也没有效果,使用点击而不是提交也没有效果。

我已启用 IE 驱动程序的调试日志记录,但输出无法帮助我了解问题所在 - 希望其他人可以。

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

有什么想法吗?

最佳答案

感谢您的帮助。回答上面提到的一些问题,我应该将其包含在原始帖子中:

-是的,确实是IE 9-我已经在所有安全区域设置了保护模式- 使用点击而不是提交没有任何区别(最初)

碰巧运行 Selenium 节点的虚拟机在夜间应用了安全更新,其中包括一个针对 IE 的更新。

起初,我收到了与之前不同的错误消息 - IE 无法找到刚刚打开的浏览器窗口,而且这些窗口也没有关闭。更新已重置所有安全设置。

重新启用保护模式后一切正常。正如理查德所说,我确实需要将查找元素更改为 .click() 而不是 .submit()。

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

关于java - Selenium:Internet Explorer 中的 NoSuchElementException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25267835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com