排除某个因素,第一优选想到正则表达式,无奈折腾半天没有成功,感觉是对元素的attrs按search在操作,$对字符串末尾检测都没什么用。
语法如下:
text_match((By.XPATH, "//tr[5]/td[11]/div"), r"[0,1]{1}.[0-9]{6}")
BeautifulSoup可以用element[‘class’]输出元素的class进行检测,但是selenium没有这样的语法,只好通过xpath进行选择:
itemList = driver.find_elements_by_xpath('//div[@id = "choose-color"]//div[@class = "dd"]//div[not(contains(@class, "disabled"))]')
stackoverflow有个参考:http://stackoverflow.com/questions/11024080/how-to-use-not-contains-in-xpath
补充xpath用法:
xpath=xpathExpression: Locate an element using an XPath expression.
xpath=//img[@alt=’The image alt text’]
xpath=//table[@id=’table1’]//tr[4]/td[2]
xpath=//a[contains(@href,’#id1’)]
xpath=//a[contains(@href,’#id1’)]/@class
xpath=(//table[@class=’stylee’])//th[text()=’theHeaderText’]/../td
xpath=//input[@name=’name2’ and @value=’yes’]
xpath=//*[text()=”right”]