Why not try the action?
Create an invisible button that you click on
((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 and result_pos_x - int pixel values
element_to_append is a reference to a jquery web element
Scroll to a button and press it (e.g. play or pause button)
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();
And insert your code with statements. In my case, I can reach some states of the Flash player through JS, so below is an example of my statement
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"));
Note that actions are supported in FF without adding your own events, but you need to add support for native events in Chrome.
The only drawback of this method is that you need to create a mapping (pixel map of each flash element) for the buttons.
source share