Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将显示块设置为xpath找到的元素_Python_Selenium_Execute Script - Fatal编程技术网

Python 将显示块设置为xpath找到的元素

Python 将显示块设置为xpath找到的元素,python,selenium,execute-script,Python,Selenium,Execute Script,我找到了我感兴趣的元素: 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错误样式是未定义的。我试过一些方法,比如link

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

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错误
样式是未定义的
。我试过一些方法,比如
link.style.display
argument.style.display
,但我不太明白这应该如何工作。您能帮忙吗?

您需要使用该元素

self.browser.execute_script('arguments[0].style.display = "block";'), link)
或者,如果您不确定
style
属性是否存在,请使用
setAttribute()

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