【发布时间】:2016-08-29 16:55:25
【问题描述】:
视频没有特定的 ID,它来自 youtube。我已经尝试使用 javascript 执行程序但无法正常工作。链接是: http://www.myhomepay.com/Tour/Nanny-Tax-Guide
【问题讨论】:
标签: html selenium-webdriver automation
视频没有特定的 ID,它来自 youtube。我已经尝试使用 javascript 执行程序但无法正常工作。链接是: http://www.myhomepay.com/Tour/Nanny-Tax-Guide
【问题讨论】:
标签: html selenium-webdriver automation
您好 Parvathy,请尝试如下所示,它将播放播放器。唯一要注意的是为什么它不播放是因为它在 iframe 内,并且要在特定 iframe 内执行操作,首先我们必须识别该 iframe,然后移动到该 iframe 以使用 webdriver 执行操作
嗨,我是一个 java 人,所以在 java 中发布答案
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.myhomepay.com/Tour/Nanny-Tax-Guide");
driver.manage().window().maximize();
// first identify the play button over the youtube video player
// Please note youtube palyer is inside the iframe hence first we have
// to identify and then switch to the i fame
List<WebElement> iframe = driver.findElements(By.tagName("iframe"));
System.out.println("Total iframe on the webpage is : "+ iframe.size());
driver.switchTo().frame(iframe.get(0));
driver.findElement(By.cssSelector(".ytp-large-play-button.ytp-button")).click();
}
更新:对于 C#,你可以像下面那样做
iFrameElement = Driver.FindElementByTagName("iFrame");
driver = Driver.SwitchTo().Frame(this.iFrameElement);
driver.FindElement(selector);
请按照 C# 重构代码。希望这会有所帮助
【讨论】: