xpath - Selenium Python: find_element_by_css_selector() using :contains() -
in selenium on python, i'm trying select element using
driver = webdriver.firefox() driver.find_element_by_css_selector("td:contains('hello world')")
which gives me error:
>>>> selenium.common.exceptions.webdriverexception: message: u'an invalid or illegal string specified'
i can select elements using many different css selectors way, using :contains() seems throw error. note: same error when try use:
driver.find_element_by_xpath("//td[contains(text(),'hello world')]")
please advise. thanks!
edit: solved!
problem solved! thank help! had 2 significant mistakes: 1.) thought :contains() accepted css3 selector (turns out not part of current spec, why couldn't select way) 2.) xpath selector have been fine except using parser assumed xpath never have spaces in it, split arguments spaces. therefore, when passed in xpath selector
//td[contains(text(),'hello world']
the parser truncated @ space after 'hello' xpath selector looked like
//td[contains(text(),'hello
which throw error. need adjust parsing read xpath selector.
thank again of fast, helpful answers!
replace find_element_by_xpath_selector
find_element_by_xpath
(there no find_element_by_xpath_selector
method):
driver = webdriver.firefox() ... driver = driver.find_element_by_xpath(u"//td[contains(text(), 'hello')]")
complete example
from selenium import webdriver driver = webdriver.firefox() driver.get('http://python.org') link = driver.find_element_by_xpath(u'//a[contains(text(), "download")]') link.click()
Comments
Post a Comment