What is arguments[0] while invoking execute_script() method through WebDriver instance through Selenium and Python?(通过 Selenium 和 Python 通过 WebDriver 实例调用 execute_script() 方法时,参数 [0] 是什么?)
问题描述
我正在尝试抓取我感兴趣的页面.为此,我需要从 HTML 中删除元素的属性.'style' 是我想要删除的.所以我从 Stackoverflow 中找到了一些代码.(我正在使用 Chrome 作为驱动程序)
I'm trying to crawl the pages that I interested in. For this, I need to remove attribute of element from HTML. 'style' is what I want to remove. So I find some codes from Stackoverflow.(i'm using Chrome for driver)
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]的作用?
What does arguments[0] do in the code? Can anyone explain arguments[0]'s roles concretely?
推荐答案
arguments
是您将 从 Python 传递到 JavaScript 的内容你想执行.
arguments
is what you're passing from Python to JavaScript that you want to execute.
driver.execute_script("arguments[0].removeAttribute('style')", element)
表示您想用存储在 element
变量中的 WebElement 来替换"arguments[0]
.
means that you want to "replace" arguments[0]
with WebElement stored in element
variable.
这与您在 JavaScript 中定义该元素相同:
This is the same as if you defined that element in JavaScript:
driver.execute_script("document.querySelector('select.m-tcol-c#searchBy').removeAttribute('style')")
您还可以将更多参数传递为
You can also pass more arguments as
driver.execute_script("arguments[0].removeAttribute(arguments[1])", element, "style")
这篇关于通过 Selenium 和 Python 通过 WebDriver 实例调用 execute_script() 方法时,参数 [0] 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 Selenium 和 Python 通过 WebDriver 实例调用 execute_script() 方法时,参数 [0] 是什么?


基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01