【发布时间】:2018-05-15 12:50:09
【问题描述】:
我只是尝试使用 selenium 网络驱动程序自动“下载 youtube 视频”。但它不起作用。在这里,我只是打开一个 youtube 视频并复制它的 URL。然后我将该 URL 粘贴到另一个页面的“SaveItOffline”选项卡中,然后单击下载。但是 URL 不会被复制。这是我的代码,
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;`enter code here`
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Keys;
public class Download {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","C:/Users/vairavan/Desktop/SELENIUM/chrome driver/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.get("http://www.youtube.com");
driver.findElement(By.id("search")).click();
driver.findElement(By.id("search")).sendKeys("short flute cover");
driver.findElement(By.id("search")).sendKeys(Keys.ENTER);
driver.findElement(By.id("dismissable")).click();
Actions action=new Actions(driver);
action.contextClick(driver.findElement(By.xpath("/html/body/ytd-app/div[1]/ytd-page-manager/ytd-watch/div[2]/div[1]/div[1]/ytd-player/div/div[1]/video"))).perform();
driver.findElement(By.xpath("/html/body/div[6]/div/div/div[1]/div[1]")).click();
driver.get("htttp://www.saveitoffline.com/");
driver.findElement(By.id("url-input")).sendKeys(Keys.CONTROL+"v");
driver.findElement(By.id("submit-url")).click();
driver.findElement(By.xpath("/html/body/section/div[3]/div/div[1]/div[2]/div")).click();
driver.findElement(By.id("download-href")).click();
}
}
【问题讨论】: