9

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
1
  • you sure you're at the page that you think you're on? Commented Oct 9, 2013 at 2:59

2 Answers 2

6

Use:

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

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

Sign up to request clarification or add additional context in comments.

7 Comments

I tried with/without WebElement, but no luck...WebElement link = driver.findElement(By.className("AddContentBTN")); Actions builder = new Actions(driver); builder.moveToElement(link).click().perform();
Sorry, I changed the code to "className" not "ClassName". Try it now.
Not working... Interestingly, I used the same code to test another link on the same page, and it works. I think this code works because the link is a subclass of div class... WebElement lOut = driver.findElement(By.className("logout")); Actions builder = new Actions(driver); Action SeriesofActions = builder.moveToElement(lOut).click().build(); SeriesofActions.perform();
The xpath for the above working click event /html/body/div[3]/div/div[2]/ul/li[4]/a
I dont think you need to use "moveToElement", as you don't need to move the mouse. Just use "click"? Of course, "click" will only work if you have properly hooked up an on click event to the "AddContentBTN" div. Double check that clicking on it manually works.
|
0

Because I stumbled upon this while looking for my own solution, this will work as well. It is for C#

driver.FindElement(By.ClassName(classNameOfOuterDiv)).FindElement(By.ClassName(nameOfClickableDiv));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.