[英]Invoking script from Selenium Python
我是selenium的新手,在弄清楚如何使用Python和Selenium Web驅動程序自動執行以下語句時遇到了麻煩。 這是可單擊的文本元素“我的按鈕標簽”。
<a class="class_a" href="javascript:f_func(46)" id="func46" ondrag="window.event.returnValue=false" onmousedown="return false;">My Button Label </a>
我已經試過了:
driver.execute_script("f_func()", 46)
和這個
driver.execute_script("f_func(46)")
但最終
selenium.common.exceptions.WebDriverException: Message: u'data[i] is undefined' ;
指向js內部的var
。
模擬46單擊參數並調用腳本並調用腳本的正確方法是什么?
編輯時:我忘記添加嘗試的第一件事
driver.find_element_by_xx().click()
也失敗了。 下面的ActionChain Api是唯一對我有用的東西。
要調用腳本,是否嘗試發送參數?
driver.execute_script("f_func(arguments[0])", 46)
但是,首先單擊有什么問題? 如果它不適合您,請嘗試使用ActionChains
。
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
# your code here
# then
ActionChains(driver).click(driver.find_element_by_id('func46')).perform()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.