2011-11-13 41 views

回答

1

使用XPath的一个随机数,包含功能的元素

//html//body//form//table//tbody//tr//td//a[contains(@href,'view.php?id=')] 
2

可以在CSS selectors使用正则表达式,

WebElement element = driver.findElement(By.cssSelector("E[foo^='bar']")); 

E[foo="bar"] an E element whose "foo" attribute value is exactly equal to "bar" 
E[foo~="bar"] an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar" 
E[foo^="bar"] an E element whose "foo" attribute value begins exactly with the string "bar" 
E[foo$="bar"] an E element whose "foo" attribute value ends exactly with the string "bar" 
E[foo*="bar"] an E element whose "foo" attribute value contains the substring "bar" 
+1

+1,但这些不是正则表达式。虽然它明显受正则表达式的影响,但该语法仅属于CSS。 –

-1

我不确定,但我认为正则表达式不会在Selenium 2中支持2

+0

我们可以在xpath中使用它。 –