2016-08-03 51 views
2
public WebDriver wd; 

@Test 
public void testSearchPage() throws InterruptedException { 

     wd.get("http://live.viddigo.com/#/video/100496?_k=224w4e"); 
     wd.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 

     WebElement video= wd.findElement(By.id("videoPlayer")); 

     JavascriptExecutor js =(JavascriptExecutor) wd ; 
     js.executeScript ("wd.findElement(By.id(\"videoPlayer\")).play();"); 
} 

On运行此代码时,显示wd未找到,尝试过文档,但没有奏效。需要播放使用appium的safari mobile上的自动化视频

+0

你真的实例化了WebDriver对象吗?在'public WebDriver wd'之后还有什么? – Josh

+0

Nop没有任何东西,如果需要在IOS模拟器 - > Safari浏览器中运行它,如果我用Safari浏览器驱动程序启动它,它会失败 –

回答

1

要在JavaScript注入中使用元素,您需要将其提供给executeScript。你可以在你的脚本中使用arguments

WebElement video = wd.findElement(By.id("videoPlayer")); 
js.executeScript("arguments[0].play();", video); 
+0

谢谢你为我工作! –

+0

这个东西仍然不适用于IOS。 –