9

我无法弄清楚如何单击 div 中的链接***

下面是我的页面资源、xpath、css 和我的失败尝试。每次尝试,我都收到了org.openqa.selenium.NoSuchElementException: no such element...

帮助?

<form id="SearchAllCampaignsForm" action="/as/update.do" method="post" name="SearchAll">
 <style>
  <script>
   <div class="body-content">
    <input type="hidden" value="" name="campCookie">
     <div id="container" class="Coptions">
      <div class="containcamps">
       <div id="dwrapper" class="dTables_wrapper" role="grid">
        <div class="owrapper">
         <div class="refresh">
          <div class="addRow">
        ***<div class="AddContentBTN" title="Add New" rel="createCampaign">Add New</div>***
          </div>
</form>

我的尝试:

@Test
 public void addCamp(){
 //WebElement link = driver.findElement(By.linkText("Add New"))

 //driver.findElement(By.xpath("//div[@class='AddContentBTN']/rel[text()='createCampaign']")).click();

 //driver.findElement(By.xpath("//a[@title = 'Add New']")).click();
 //Actions builder = new Actions(driver);
 //builder.moveToElement(addCamp).click().perform();
 //driver.findElement(By.cssSelector("div.wrapper div.row-fluid form#SearchAllCampaignsForm div.body-content div.container div#dataTable_wrapper.dataTables_wrapper div.optionswrapper div.addRow div.AddContentBTN")).click();
}

xPath 和 CSS:

/html/body/div[3]/div/form/div/div[2]/div/div/div[2]/div

html body div.wrapper div.row-fluid form#SearchAllCampaignsForm div.body-content div.container div#dataTable_wrapper.dataTables_wrapper div.optionswrapper div.addRow div.AddContentBTN
4

2 回答 2

6

利用:

driver.findElement(By.className("AddContentBTN")).click();

如果您不知道,可以在此处找到 Selenium 的“By”类的文档。

于 2013-10-08T23:42:53.227 回答
0

因为我在寻找自己的解决方案时偶然发现了这一点,所以这也可以。它适用于 C#

driver.FindElement(By.ClassName(classNameOfOuterDiv)).FindElement(By.ClassName(nameOfClickableDiv));
于 2013-12-20T23:48:17.030 回答