3

過去に Selenium RC を使用したことがありますが、webdriver は初めてです。アプリには 3 つのリンクがあります。通知、メッセージ、接続。通知をクリックすると、通知ドロップボックスが表示されます。メッセージをクリックすると、メッセージ ドロップ ボックスが表示され、接続をクリックすると、接続ドロップ ボックスが表示されます。スクリプトでは、通知リンクをクリックし、通知ドロップ ボックスを待ってから、通知ドロップボックスをアサートします。メッセージと接続の順序についても同じです。通知シーケンスは正しく機能します。メッセージでは、メッセージ リンクをクリックしてから、メッセージ ドロップ ボックス リンクを待機してハングします。すべての行の後に print コマンドを置いたので、これを知っています。これが私のコードです:

 driver.findElement(By.xpath("//a[@id='notifications-page-button']")).sendKeys("\n");
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='notifications-dropdown-list']//li//div[@class='message']")));
Assert.assertTrue(isElementPresent(By.xpath("//div[@id='notifications-dropdown-list']//li//div[@class='message']")), "Notifications drop box was not displayed");

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@id='messages-page-button']")));

driver.findElement(By.xpath("//a[@id='messages-page-button']")).sendKeys("\n");
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class='sf_messages_list dropdown']//li//div[@class='message']"))); //This is the line where the script hangs. If I remove this line and the next line and continue with just the click commands, they work. But when I have this line and the next, the remaining click commands are not executed

Assert.assertTrue(isElementPresent(By.xpath("//div[@class='sf_messages_list dropdown']//li//div[@class='message']")), "Messages drop box was not displayed");

wait.until(ExpectedConditions.presenceOfElementLocated(By.id("connections-page-button"))); 
driver.findElement(By.id("connections-page-button")).click()

メッセージ セクションの HTML は次のとおりです。

<li class="icon mm open">
<a id="messages-page-button" class="mm" href="#">
<span class="icon"></span>
<span class="badge hidden_elem">
<strong>
<em>0</em>
</strong>
</span>
</a>
<div class="dropdown-holder">
<div class="sf_messages_list dropdown" data-eventprefix="mainmenu_messages">
<div class="tb-dropdown-header">Messages</div>
<div class="tb-dropdown-body" data-url="/messages/dropdown">
<div class="document-title" style="display: none; !important"> - Dropdown Messages</div>
<div id="messages_list_view_76345" class="message-threads-listview">
<ul>
<div class="no_items hidden_elem">
</div>
</div>
<div class="tb-dropdown-footer" style="display: block;">
</div>
<span class="shadow-hide"></span>
</div>
</li>

通知セクションの HTML は次のとおりです。

<li class="icon mm">
<a id="notifications-page-button" class="mm" href="#">
<span class="icon"></span>
<span class="badge hidden_elem">
<strong>
<em>0</em>
</strong>
</span>
</a>
<div class="dropdown-holder">
<div id="notifications-dropdown-list" class="sf_notifications_list dropdown" data-eventprefix="mainmenu_notifications">
<div class="tb-dropdown-header">Notifications</div>
<div class="tb-dropdown-body" data-url="/notifications/dropdown"></div>
<div class="tb-dropdown-footer">
<a class="view_all" href="/notifications/view">View All Notifications</a>
</div>
</div>
<span class="shadow-hide"></span>
</div>
</li>

上記のコードは IE で動作します。問題は、要素が見つからないことではないようです。Selenium 2.25.0 を使用しています。3.6、7、11、13、15、16 など、さまざまなバージョンの FF を試しましたが、どれも機能しませんでした。また、スクリプトがハングするだけです。Eclipseでエラーをスローすることさえありません。スクリプトを約 11 時間実行したことがありますが、それでもエラーは発生しませんでした。

この問題を解決するためにさらに情報が必要な場合はお知らせください。

ありがとう!

4

2 に答える 2

1

以前のバージョンの Selenium Webdriver で同様のことが起こりました。そして、私に何が起こっているのか、私も無知でした。最終的には、Selenium の最新バージョンに更新することでうまくいきましたが、2.25.0 が最新であるため、少なくとも、更新によって解決されるまで使用していた回避策を紹介します。

ボタンをクリックする必要があるときはいつでも、(あなたに関しては)何も起こりませんでした。したがって、回避策は、ボタンをクリックすると、Enterキーイベントも送信することでした。

もう少し詳しく言うと:

 WebElement buttonWhereClickingDoesNotWork = driver.findElement(By.id("messages-page-button");
buttonWhereClickingDoesNotWork.click();
buttonWhereClickingDoesNotWork.sendKeys(Keys.ENTER);

はい、その回避策です。はい、それは良くありません。はい、それは私を助けました。

また:いいえ、Seleniumの更新が私の場合に役立ったので、これの根本的な原因はわかりません...

于 2012-10-23T14:38:01.483 に答える
0

これは、Facebook ログインと何らかの関係があるようです。ウィンドウハンドルを正しく切り替えていますか? また、暗黙のタイムアウトは何ですか。デフォルトでは 30 秒に設定されているため、スクリプトがエラーなしで 11 時間実行できるかどうかはわかりません。

これらを試すことができますか

1)は存在しないと推測していますが、スクリプトは実際にはそのステップでスタックしており、次のステップではスタックしていません。className("message")これにはクリックが含まれます。

driver.findElement(By.id("notifications-page-button")).click();
wait.until(driver.findElement(By.id("messages-page-button")));#<<-- Changed the element to wait for

//The code works untill here. But on the next command that clicks messages link, it hangs
driver.findElement(By.id("messages-page-button")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("username"))));

2)その待機要素を削除します

driver.findElement(By.id("notifications-page-button")).click();
#removed this wait for element

//The code works untill here. But on the next command that clicks messages link, it hangs
driver.findElement(By.id("messages-page-button")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("username"))));

アップデート


これを試してください...

driver.findElement(By.id("notifications-page-button")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("message"))));

//The code works untill here. But on the next command that clicks messages link, it hangs
driver.findElement(By.id("messages-page-button")).click();
wait.until(driver.findElement(By.id("connections-page-button"))); # changed it to wait for the element that you will next work with

driver.findElement(By.id("connections-page-button")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("connections-listview"))));

また、Web 要素の HTML スニペットを提供していただければ、ロケーターについて確信が持てません。

于 2012-10-23T14:36:16.537 に答える