您可以使用
WebDriver.execute_script。例如:
from selenium import webdriverdriver = webdriver.Firefox()driver.get('http://jsfiddle.net/falsetru/mLGnB/show/')elem = driver.find_element_by_css_selector('div.dijitReset>input[type=hidden]')driver.execute_script(''' var elem = arguments[0]; var value = arguments[1]; elem.value = value;''', elem, '2013-11-26')
更新
from selenium import webdriverdriver = webdriver.Firefox()driver.get('http://matrix.itasoftware.com/')elem = driver.find_element_by_xpath( './/input[@id="ita_form_date_DateTextBox_0"]' '/following-sibling::input[@type="hidden"]')value = driver.execute_script('return arguments[0].value;', elem)print("Before update, hidden input value = {}".format(value))driver.execute_script(''' var elem = arguments[0]; var value = arguments[1]; elem.value = value;''', elem, '2013-11-26')value = driver.execute_script('return arguments[0].value;', elem)print("After update, hidden input value = {}".format(value))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)