我正在通過selenium的實踐,其中xpath在firefox xpath extesion中驗證,但不是在python硒中驗證。在硒中運行Xpath的文本()
例如去here和應用的XPath //span[@class='tableNode']/text()[preceding-sibling::br and following-sibling::br]
它工作在Firefox擴展,但不是在表達硒像driver.find_elements_by_xpath("//span[@class='tableNode']/text()[preceding-sibling::br and following-sibling::br]")
例外,我現在所面臨
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: The given selector //span[@class='tableNode']/text()[preceding-sibling::br and following-sibling::br] is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: The result of the xpath expression "//span[@class='tableNode']/text()[preceding-sibling::br and following-sibling::br]" is: [object Text]. It should be an element.
任何幫助是值得歡迎的。
這個js用於填充元素的數組無法用於網站https://www.google.com/ncr#q=chiropractors%2BNew+York,+NY&rflfq=1&rlha=0&tbm=lcl它爲xpath提供了截斷的商業名稱' // div [@class ='_ pl _ki']/descendant-or-self :: text()[1]''''只喜歡'百老匯'而不是'百老匯整脊療養' – SIslam
您選擇的索引[1] –
啊! '[2]'選擇評論,例如'4 reviews etc.''但事實是,''之後的所有文字都被排除在前面提到的'Chiropractic&Wellness'之外! –
SIslam