【问题标题】:set display block to an element found by xpath将显示块设置为 xpath 找到的元素
【发布时间】:2020-04-25 01:06:36
【问题描述】:

我找到了我感兴趣的元素:

LINKS = (By.PARTIAL_LINK_TEXT, "link_to")
links = self.browser.find_elements(*self.LINKS)

他们现在为None 设置了display,我想向他们展示:

for link in links:
  self.browser.execute_script("style.display = 'block';", link)

但是给了我 js 错误style is undefined。我已经尝试过link.style.displayargument.style.display 之类的东西,但我真的不明白它应该如何工作。你能帮忙吗?

【问题讨论】:

    标签: python selenium execute-script


    【解决方案1】:

    你需要用到元素

    self.browser.execute_script('arguments[0].style.display = "block";'), link)
    

    或者如果您不确定style 属性是否存在,请使用setAttribute()

    self.browser.execute_script('arguments[0].setAttribute("style", "display:block");'), link)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      • 2020-06-14
      • 2018-08-30
      • 1970-01-01
      相关资源
      最近更新 更多