NoSuchElementException:无法找到元素

时间:2014-04-30 07:54:40

标签: selenium selenium-webdriver webdriver

我想点击链接要求,我尝试了下面的代码,但他们都给出了错误。

  1. driver.findElement(By.partialLinkText("Requirements")).click();

  2. driver.findElement(By.xpath("//a[contains(.,'Requirements')")).click();

  3. driver.findElement(By.xpath("//a[contains(text().,'Requirements')] ")).click()

  4. driver.findElement(By.xpath("//a[@href='lib/general/frmWorkArea.php?feature=reqSpecMgmt")).click();

    <frameset framespacing="0" frameborder="0" rows="70,*">
      <frame scrolling="no" noresize="noresize" name="titlebar" src="lib/general/navBar.php?tproject_id=0&tplan_id=0&updateMainPage=1">
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
       <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
       <head>
       <body style="min-width: 800px;">
       <div style="float:left; height: 100%;">
      <div class="menu_title">
    
    <div class="menu_bar" style="margin: 0px 5px 0px 135px;">
    <div style="display: inline; float: right;">
    <a 1''="" tabindex="" accesskey="h" target="_parent" href="index.php">Desktop</a>
    |
     <a 2''="" tabindex="" accesskey="r" target="mainframe" href="lib/general/frmWorkArea.php?           feature=reqSpecMgmt">Requirements</a>
    |
     <a 3''="" tabindex="" accesskey="t" target="mainframe" href="lib/general/frmWorkArea.php?feature=editTc">Test Specification</a>
     </div>
    

3 个答案:

答案 0 :(得分:1)

在尝试使用之前,您必须切换到包含该元素的框架:

driver.switchTo().frame("titlebar");

答案 1 :(得分:1)

IWebElement frame = driver.FindElementByName("titlebar");
driver.SwitchTo().Frame(frame);

然后尝试找到所需的元素..

答案 2 :(得分:0)

请使用以下XPath值:

    driver.findElement(By.xpath("//a[@accesskey='r']")).click();