javascript - 通过 Selenium 和 Python 通过 WebDriver 实例调用 execute_script() 方法时 arguments[0] 是什么?

标签 javascript python selenium selenium-webdriver webdriver

我正在尝试抓取我感兴趣的页面。为此,我需要从 HTML 中删除元素的属性。 “风格”是我想要删除的。所以我从 Stackoverflow 找到了一些代码。(我使用 Chrome 作为驱动程序)

element = driver.find_element_by_xpath("//select[@class='m-tcol-c' and @id='searchBy']")
driver.execute_script("arguments[0].removeAttribute('style')", element)

arguments[0] 在代码中做了什么?谁能具体解释一下arguments[0]的作用?

最佳答案

arguments 是您从 Python 传递给要执行的 JavaScript 的内容。

driver.execute_script("arguments[0].removeAttribute('style')", element) 

表示您要用存储在 element 变量中的 WebElement“替换”arguments[0]

这与您在 JavaScript 中定义该元素是一样的:

driver.execute_script("document.querySelector('select.m-tcol-c#searchBy').removeAttribute('style')")

你也可以传递更多的参数作为

driver.execute_script("arguments[0].removeAttribute(arguments[1])", element, "style")

关于javascript - 通过 Selenium 和 Python 通过 WebDriver 实例调用 execute_script() 方法时 arguments[0] 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52273298/

相关文章:

javascript - 在 HTML 中注入(inject) Javascript 片段

python - 用 matplotlib 表示体素

javascript - jQuery JSON 错误 : Syntax error, 无法识别的表达式

需要 JavaScript OOP 辅助

python - 在使用 Python 的 vscode 中,ctrl+F5 总是要求输入 "select environment"

python - 根据 Pandas 中的前后行计算一行中的值

python - 无法在我的脚本中应用显式等待

c# - 如何使用 Selenium、Webdriver、C# 在 Esri map 上绘制多边形

selenium - 在 Selenium Webdriver 中选择单选按钮时出现问题

javascript - 原型(prototype)中的 getAttribute 但抛出 undefined