2 回答

TA貢獻1810條經驗 獲得超4個贊
arguments
是您從 Python傳遞給要執行的JavaScript 的內容。
driver.execute_script("arguments[0].removeAttribute('style')", element)
意味著您想arguments[0]
用存儲在element
變量中的WebElement “替換” 。
這與您在 JavaScript 中定義該元素是一樣的:
driver.execute_script("document.querySelector('select.m-tcol-c#searchBy').removeAttribute('style')")
您還可以傳遞更多參數作為
driver.execute_script("arguments[0].removeAttribute(arguments[1])", element, "style")

TA貢獻1946條經驗 獲得超3個贊
根據文檔execute_script()
方法在當前窗口/框架中同步執行JavaScript并定義為:
execute_script(script, *args)
Synchronously Executes JavaScript in the current window/frame.
Where:
script: The JavaScript to execute.
*args: Any applicable arguments for your JavaScript.
根據您提供的示例:
element = driver.find_element_by_xpath("//select[@class='m-tcol-c' and @id='searchBy']")
driver.execute_script("arguments[0].removeAttribute('style')", element)
arguments[0].removeAttribute('style'): 指要通過execute_script()方法同步執行的腳本,其中:
arguments[] 將是將通過的元素的引用 *args
removeAttribute() 是要執行的方法。
style是removeAttribute()將調用該方法的屬性。
element是傳遞給的WebElement的引用arguments[0]
添加回答
舉報