【问题标题】:get the value of <param> in <object> with selenium IE driver使用 selenium IE 驱动程序获取 <object> 中 <param> 的值
【发布时间】:2020-03-07 06:55:31
【问题描述】:

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 是索引

【问题讨论】:

    标签: python selenium-webdriver selenium-iedriver


    【解决方案1】:

    使用 diriver.page_souce 到 gei html,并使用 re.findall() 来匹配数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 2017-01-07
      相关资源
      最近更新 更多