3

内部 Web アプリケーション用の Selenium スクリプトを、Selenium IDE から Java の RemoteWebDrivers を使用した Selenium Grid セットアップに移植しようとしています。

スクリプトは 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.

(最後の 2 行は数回繰り返されます)

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

何か案は?

4

5 に答える 5

1

助けてくれてありがとう。上記の質問のいくつかに答えるには、元の投稿に含める必要がありました。

-はい、確かに IE 9 です -私はすでにすべてのセキュリティ ゾーンで保護モードを有効に設定していました -送信の代わりにクリックを使用しても違いはありませんでした (最初は)

たまたま、Selenium ノードを実行している VM が夜間にセキュリティ更新プログラムを適用し、IE 用のセキュリティ更新プログラムが含まれていました。

最初に、以前とは異なるエラー メッセージが表示されました。IE は開いたばかりのブラウザ ウィンドウを見つけることができず、ウィンドウも閉じられませんでした。アップデートにより、すべてのセキュリティ設定がリセットされました。

保護モードを再度有効にすると、すべてが機能するようになりました。Richard が指摘したように、find 要素を .submit() ではなく .click() に変更する必要がありました

そのため、すべてが機能するようになりましたが、その理由はわかりません。再度、感謝します!

于 2014-08-13T10:04:47.777 に答える
0

InternetExplorerDriver通常の代わりに使用してみてくださいRemoteWebDriver。違いはありませんが、IEではすべてが可能です-.-

同様の問題が発生し、最終的には次のコードが機能します。

@Before
public void setUp() {
   //... some irrelevant Code ... 

   System.setProperty("webdriver.ie.driver", "Path to IEDriver.exe");
   InternetExplorerDriver driver = new InternetExplorerDriver();

   //... some irrelevant Code ...
}
于 2014-08-13T09:42:32.467 に答える
0

次の方法でコードを記述できます。

while(true) {
    try {
        driver.findElement(By.linkText("space probe")).submit();
        break;
    } catch (Exception e) {
        continue;
    }
}

スレッドが成功するまで検索するように、このようにコードを記述します。を使用する場合implicitlyWait、ブラウザはその最大時間だけ待機します。しかし、ブラウザー ページの読み込みは完了していても、必要な部分が ajax 呼び出しによって読み込まれる場合があります。その場合、プログラムはエラーをスローします。

于 2015-09-12T17:34:57.407 に答える