html如下:
<OBJECT id="IndiDocX" CODEBASE="/IndiDoc.CAB#version=4,5,0,132" width=500 height=201 VIEWASTEXT>
.........
<PARAM NAME="IDNUM" VALUE="4090">
<PARAM NAME="Editable" VALUE="false">
<PARAM NAME="Nodelfiles" VALUE="\adad.xlsx\1111.sep\2222.gw">
我想通过IE驱动程序中的xpath获取PARAM[@name="Nodelfiles"]
的值
我的代码:
attr = driver.find_element_by_xpath('//object[@id="IndiDocX"]/param[@name="Nodelfiles"]').get_attribute('value')
消息:
Traceback (most recent call last):
File "e:\Dropbox\17.Develop\5.Projects\auto.oa\main.py", line 158, in <module>
main()
File "e:\Dropbox\17.Develop\5.Projects\auto.oa\main.py", line 154, in main
insert_to_db('DC5EF2F7F4DB79E648258523002C628E')
File "e:\Dropbox\17.Develop\5.Projects\auto.oa\main.py", line 138, in insert_to_db
attr = driver.find_element_by_xpath(
File "C:\Users\A\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webelement.py", line 139, in get_attribute
attributeValue = self.parent.execute_script(
File "C:\Users\A\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 634, in execute_script
return self.execute(command, {
File "C:\Users\A\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\A\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: Error executing JavaScript
如何获得价值 我用这个可以通过索引获取,但是不能用名字
js = 'return document.getElementById("IndiDocX").getElementsByTagName("PARAM")[24].getAttribute("value");'
attr = driver.execute_script(js)
print(attr)
24是索引
答案 0 :(得分:1)
使用diriver.page_souce来gei html,并使用re.findall()来匹配数据