xpath locator not work as expected to locate a "<a" element with compound class name
This line will not work but I think I have used correct xpath?
driver.findElement(By.xpath("//a[contains(@class,'cke_button_bold')]")).click();
to locate a button li开发者_如何转开发ke below :
<a id="cke_73" class="cke_off cke_button_bold">
id is a dynamic number so can be used as fixed locator here. And class is a compound class which is not supported by WebDriver findElement method...
I created simple html file and your xpath works with FirefoxDriver in WebDriver 2.1.0.
Also you can try to use
driver.findElement(By.className("cke_button_bold"))
Classname is supported by webdriver Api
Step 1:
Find the CSS Selector
Possible CSS Selectors here:
css=a[id*='cke']
css=.cke_off cke_button_bold
The above can be used Or Already we are having the method .ClassName But for avoiding duplication of Elements and Ambiguity we can use CSS Selector.
精彩评论