python - Run text() of Xpath in selenium -


i going through selenium practice xpath validates in firefox xpath extesion not in python selenium.

e.g. go here , apply xpath //span[@class='tablenode']/text()[preceding-sibling::br , following-sibling::br] works in firefox extension not in selenium expression driver.find_elements_by_xpath("//span[@class='tablenode']/text()[preceding-sibling::br , following-sibling::br]")

exception facing

    traceback (most recent call last):       debug probe, prompt 17, line 1       file "c:\python27\arcgis10.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 270, in find_elements_by_xpath         return self.find_elements(by=by.xpath, value=xpath)       file "c:\python27\arcgis10.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 739, in find_elements         {'using': by, 'value': value})['value']       file "c:\python27\arcgis10.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute         self.error_handler.check_response(response)       file "c:\python27\arcgis10.3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_response         raise exception_class(message, screen, stacktrace)     selenium.common.exceptions.invalidselectorexception: message: given selector //span[@class='tablenode']/text()[preceding-sibling::br , following-sibling::br] either invalid or not result in webelement. following error occurred:     invalidselectorerror: result of xpath expression "//span[@class='tablenode']/text()[preceding-sibling::br , following-sibling::br]" is: [object text]. should element. 

any welcome.

for multiple returning record:

driver.get("http://www.hotleathers.com/front-printed-t-shirts-c1232.aspx?s=orderby%20asc&&v=all")  returntext = [] returntext = self.driver.execute_script("var iterator = document.evaluate(\"//span[@class='tablenode']/text()[preceding-sibling::br , following-sibling::br]\", document, null, xpathresult.ordered_node_iterator_type, null ); var arrayxpath = new array();  var thisnode = iterator.iteratenext(); while (thisnode) {arrayxpath.push(thisnode.textcontent);  thisnode = iterator.iteratenext(); }    return arrayxpath;")  item in returntext:     print item 

pure javascript code is:

var iterator = document.evaluate('//span[@class='tablenode']/text()[preceding-sibling::br , following-sibling::br]", documentnode, null, xpathresult.unordered_node_iterator_type, null );  try {   var thisnode = iterator.iteratenext();    while (thisnode) {     alert( thisnode.textcontent );     thisnode = iterator.iteratenext();   }  } catch (e) {   dump( 'error: document tree modified during iteration ' + e ); } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -