Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click on a <div class >link using WebDriver

I am not able to figure out how to click the link within div***

Below is my page resource, xpath, css & my failure attempts. With each of the attempts, I received org.openqa.selenium.NoSuchElementException: no such element...

Help?

<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>

My attempts:

@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 and 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
like image 884
Insane Avatar asked Oct 08 '13 23:10

Insane


1 Answers

Use:

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

In case you don't know, documentation for Selenium's "By" class can be found here.

like image 200
Ben Smith Avatar answered Sep 23 '22 20:09

Ben Smith