下面是HTML代码...这里我只想点击span标签中的cssselector(span.icon_edit ClsUpdate)..
<div class="final_textarea">
<div class="tab_lable_right">
<textarea rows="2" cols="50" id="txttab_2" readonly="readonly" class="input col_10 input_medium box_radius clscopypaste" oncopy="return false" oncut="return false" data-columnid="20" data-columnname="Member Services Link
" data-preval="ABC insurance">ABC insurance</textarea>
</div>
<span data-columnid="20" data-columnname="Member Services Link" data-preval="ABC insurance" class="icon_edit ClsUpdate"></span>
</div>
情景:
我的网络驱动程序代码是;
WebElement mainMenu = driver.findElement(By.xpath("//*[@id='txttab_2']"));
mainMenu.click();
Thread.sleep(3000);
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class=\"icon_edit ClsUpdate\"]")));
element.click();
错误;
Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 20 seconds waiting for element to be clickable: By.xpath: //span[@class="icon_edit ClsUpdate"]
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
System info: host: 'Axxxxx-J008', ip: '10.10.6.22', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_25'
答案 0 :(得分:3)
您可以在this网站上试用以下xpath:
//span[@class="icon_edit ClsUpdate"]
所以,你的代码是:
WebElement link = driver.findElement(By.xpath("//span[@class=\"icon_edit ClsUpdate\"]"));
//wait for the element to be clickable
link.click();
答案 1 :(得分:0)
//I'm assuming your selector's are correct
WebElement mainMenu = driver.findElement(By.xpath("//*[@id='txttab_2']"));
mainMenu.click();
//this bit below searches inside the text area which is what i think you need and not the whole page.
final WebElement link = mainMenu.findElement(By.xpath("//span[@class=\"icon_edit ClsUpdate\"]"));
link.click();