Click the <div class> link using WebDriver

I can't figure out how to click a link in a div ***

Below is the page resource, xpath, css and my failure attempts. On every attempt, I got org.openqa.selenium.NoSuchElementException: no such element...

reference

 <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 
+6
source share
2 answers

Using:

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

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

+5
source

Since I stumbled upon this while looking for my own solution, this will work too. This is for C #

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

Source: https://habr.com/ru/post/955539/


All Articles