Java 获取异常org.openqa.selenium.NoSuchElementException:未找到包含文本的链接

Java 获取异常org.openqa.selenium.NoSuchElementException:未找到包含文本的链接,java,selenium-webdriver,Java,Selenium Webdriver,我正在尝试创建一个将连接到的应用程序。通常在该网站上,我们需要粘贴youtube视频url,然后单击转换视频按钮。转换完成后,会出现带有下载链接的Div。所有我需要发送点击命令到下载链接。我已经为此编写了如下代码: public class Example { public static void main(String[] args) { WebDriver driver = new HtmlUnitDriver(); driver.get("http://www.yout

我正在尝试创建一个将连接到的应用程序。通常在该网站上,我们需要粘贴youtube视频url,然后单击转换视频按钮。转换完成后,会出现带有下载链接的Div。所有我需要发送点击命令到下载链接。我已经为此编写了如下代码:

public class Example {
public static void main(String[] args) {

    WebDriver driver = new HtmlUnitDriver();

    driver.get("http://www.youtube-mp3.org/");

    // Find the text input element by its id
    WebElement element = driver.findElement(By.id("youtube-url"));

    element.clear();
    element.sendKeys("http://www.youtube.com/watch?v=KMU0tzLwhbE");

    driver.findElement(By.id("submit")).submit();

    driver.findElement(By.linkText("Download")).click();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    System.out.println(driver.getPageSource());

    driver.quit();
}
}

当我运行此命令时,会出现以下异常:

  Exception in thread "main" org.openqa.selenium.NoSuchElementException: No link found with text:  
    Download
    For documentation on this error,please visit:  http://seleniumhq.org/exceptions/no_such_element.html
   Build info: version: '2.9.0', revision: '14289', time: '2011-10-20 21:53:56'
   System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
   Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByLinkText(HtmlUnitDriver.java:650)
at org.openqa.selenium.By$ByLinkText.findElement(By.java:235)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1221)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:974)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1218)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:394)
at com.general.Example.main(Example.java:38)
我对硒相当陌生。请帮帮我


谢谢。

按下提交按钮后,您需要等待链接变为可点击

import org.openqa.selenium.support.ui.ExpectedConditions;

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Download")));