我无法弄清楚如何点击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
答案 0 :(得分:5)
使用:
driver.findElement(By.className("AddContentBTN")).click();
如果你不知道,Selenium&#34; By&#34;可以找到班级here。
答案 1 :(得分:0)
因为我在寻找自己的解决方案时偶然发现了这一点,所以这也会有效。它适用于C#
driver.FindElement(By.ClassName(classNameOfOuterDiv)).FindElement(By.ClassName(nameOfClickableDiv));