アクションを試してみませんか?
クリックする非表示のボタンを作成する
((JavascriptExecutor) driver).executeScript("var mybutton = $('<button/>', {id: 'invisbutton', class: 'invisbutton',text: '', style: 'position:absolute; width:20px; height:20px;top:" + result_pos_y + "px;left:" + result_pos_x + "px;visibility:hidden'}); $('" + element_to_append + "').append(mybutton);");
result_pos_y
およびresult_pos_x
ピクセルの int 値です
element_to_append
jquery webelementリファレンスです
ボタンに移動してクリックします (再生または一時停止ボタンのように)
Actions builder = new Actions(driver.getWebDriver());
builder.moveToElement(driver.findElement(By.xpath("//button[@id='invisbutton']"))).build().perform();
builder.moveToElement(driver.findElement(By.xpath("//button[@id='invisbutton']"))).click().build().perform();
そして、アサートを使用してコードを挿入します。私の場合、JS を介していくつかの Flash プレーヤーの状態に到達できるため、以下は私のアサートの例です。
String brightcove_id = driver.findElement(By.xpath("//div[@id='bcplayer-container']//object")).getAttribute("id");
((JavascriptExecutor) driver).executeScript("brightcove.api.getExperience('" + brightcove_id + "').getModule(brightcove.api.modules.APIModules.VIDEO_PLAYER).getIsPlaying( function(isPlaying) { alert(isPlaying)})");
driver.pause(200);
String alert_text = driver.switchTo().alert().getText();
driver.switchTo().alert().accept();
assertTrue("Video is not stopped after clicking pause button", alert_text.equals("false"));
アクションは、ネイティブ イベントを追加しなくても FF でサポートされますが、Chrome でネイティブ イベント サポートを追加する必要があることに注意してください。
この方法の唯一の欠点は、ボタンのマッピング (すべてのフラッシュ要素のピクセル マップ) を作成する必要があることです。