Python 当通过xpath枚举元素时,Selenium chromedriver异常

Python 当通过xpath枚举元素时,Selenium chromedriver异常,python,selenium,arm,selenium-chromedriver,chromium,Python,Selenium,Arm,Selenium Chromedriver,Chromium,我正在尝试将Selenium脚本从Firefox转换为Chrome。代码与预期的工作方式相同。geckodriver不能很好地支撑手臂,所以我尝试使用Chrome Chromium和chromedriver在使用驱动程序时导致异常。通过xpath('/*[@id]')查找元素。。异常为selenium.common.exceptions.WebDriverException:Message:chrome不可访问 问题是什么?如何解决 这是测试程序 $cat test.py #!/usr/bin

我正在尝试将Selenium脚本从Firefox转换为Chrome。代码与预期的工作方式相同。geckodriver不能很好地支撑手臂,所以我尝试使用Chrome

Chromium和chromedriver在使用
驱动程序时导致异常。通过xpath('/*[@id]')查找元素。
。异常为
selenium.common.exceptions.WebDriverException:Message:chrome不可访问

问题是什么?如何解决


这是测试程序

$cat test.py
#!/usr/bin/env蟒蛇3
导入系统
进口硒
从打包导入版本
从selenium导入webdriver
#从selenium.webdriver.firefox.options导入选项
从selenium.webdriver.chrome.options导入选项
def main():
#################################################
如果version.parse(selenium.\uuuuuu version\uuuuuu)>=version.parse(“3.0”):
opts=Options()
opts.headless=True
opts.binary_location=“/usr/bin/chromium”
#driver=webdriver.Firefox(options=opts)
driver=webdriver.Chrome(Chrome\u options=opts)
驱动程序。最大化_窗口()
其他:
#profile=webdriver.FirefoxProfile()
profile=webdriver.ChromeProfile()
profile.headless=True
profile.binary_location=“/usr/bin/chromiu”
#driver=webdriver.Firefox(配置文件)
driver=webdriver.Chrome(配置文件)
驱动程序。最大化_窗口()
agent=driver.execute\u脚本('return navigator.userAgent')
打印(代理)
#################################################
驱动程序。获取(“https://complaints.donotcall.gov/complaint/complaintcheck.aspx")
驱动程序。隐式等待(3)
ids=driver。通过xpath('/*[@id]'查找元素
对于ID中的ii:
打印(ii.get_属性('id'))
#################################################
driver.quit()
如果名称=“\uuuuu main\uuuuuuuu”:
main()

当尝试使用Chrome和chromedriver枚举XPath时,这里是一个例外

$。/test.py
Mozilla/5.0(X11;Linux armv7l)AppleWebKit/537.36(KHTML,类似Gecko)无头Chrome/72.0.3626.122 Safari/537.36
回溯(最近一次呼叫最后一次):
文件“/test.py”,第50行,在
main()
文件“/test.py”,第41行,主
ids=driver。通过xpath('/*[@id]'查找元素
文件“/usr/local/lib/python3.5/dist packages/selenium/webdriver/remote/webdriver.py”,第410行,按xpath查找元素
返回self.find_元素(by=by.XPATH,value=XPATH)
文件“/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py”,第1007行,在find_元素中
'value':value})['value']或[]
文件“/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py”,执行中第321行
self.error\u handler.check\u响应(响应)
文件“/usr/local/lib/python3.5/dist packages/selenium/webdriver/remote/errorhandler.py”,第242行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.WebDriverException:消息:无法访问chrome
(会话信息:无头镀铬=72.0.3626.122)
(驱动程序信息:chromedriver=72.0.3626.122,平台=Linux 4.4.132+armv7l)

此代码:

ids = driver.find_elements_by_xpath('//*[@id]')
for val in ids:
    print(val.get_attribute('id'))
应该返回如下内容:

Head1
_fed_an_ua_tag
bdyComplaint
top
changeLang
topnav
navbtn
mobileChangeLang
Form1
__EVENTTARGET
__EVENTARGUMENT
__VIEWSTATE
__VIEWSTATEGENERATOR
__EVENTVALIDATION
StepOnePanel
StepOneEntryPanel
ErrorMsg
PhoneTextBox
DateOfCallTextBox
TimeOfCallDropDownList
ddlMinutes
PrerecordMessageYESRadioButton
PrerecordMessageNORadioButton
PhoneCallRadioButton
MobileTextMessageRadioButton
ddlSubjectMatter
spnTxtSubjectMatter
txtSubjectMatter
StepOneContinueButton
hdnBlockBack
hdnPhoneChecked
hdnCompanyChecked
hdnPhoneNumber

这是版本号

Tinkboard$python3——版本
Python 3.5.3
Tinkboard$/usr/bin/chromium——版本
Chromium 72.0.3626.122构建在Debian 9.8上,运行在Debian 9.8上
Tinkboard$/usr/bin/chromedriver——版本
ChromeDriver 72.0.3626.122

问题似乎在于,Chrome浏览器的名称在不同的操作系统和平台上是一个移动目标。此代码避免了x86_64和Linux上的ARM上的异常:

def get_chrome():
"""
用于定位chrome浏览器的辅助功能。
"""
如果os.path.isfile('/usr/bin/chromium browser'):
返回“/usr/bin/chromium browser”
如果os.path.isfile('/usr/bin/chromium'):
返回“/usr/bin/chromium”
如果os.path.isfile('/usr/bin/chrome'):
返回'/usr/bin/chrome'
如果os.path.isfile('/usr/bin/google chrome'):
返回“/usr/bin/googlechrome”
一无所获
然后像这样使用它:

if version.parse(selenium.\uuuuu version\uuuuuu)>=version.parse(“3.0”):
opts=Options()
opts.binary_location=get_chrome()
opts.add_参数('--headless')
opts.add_参数('--no sandbox')
opts.add_参数('--disable dev shm usage')
driver=webdriver.Chrome(Chrome\u options=opts)
驱动程序。最大化_窗口()
其他:
profile=webdriver.ChromeProfile()
profile.headless=True
profile.binary\u location=get\u chrome()
driver=webdriver.Chrome(配置文件)
驱动程序。最大化_窗口()

问题似乎在于,Chrome浏览器的名称在不同的操作系统和平台上是一个移动目标。此代码避免了x86_64和Linux上的ARM上的异常:

def get_chrome():
"""
用于定位chrome浏览器的辅助功能。
"""
如果os.path.isfile('/usr/bin/chromium browser'):
返回“/usr/bin/chromium browser”
如果os.path.isfile('/usr/bin/chromium'):
返回“/usr/bin/chromium”
如果os.path.isfile('/usr/bin/chrome'):
返回'/usr/bin/chrome'
如果os.path.isfile('/usr/bin/google chrome'):
返回“/usr/bin/googlechrome”
一无所获
然后像这样使用它:

if version.parse(selenium.\uuuuu version\uuuuuu)>=version.parse(“3.0”):
opts=Options()
opts.binary_location=get_chrome()
opts.add_参数('--headless')
opts.add_参数('--no sandbox')
opts.add_参数('--disable dev shm usage')
driver=webdriver.Chrome(Chrome\u options=opts)
驱动程序。最大化_窗口()
其他:
profile=webdriver.ChromeProfile()
profile.headless=True
profile.binary\u location=get\u chrome()
driver=webdriver.Chrome(配置文件)
驱动程序。最大化_窗口()

当我浏览时,没有注意到arm的评论