selenium--JS元素的操做

#####################################################
## JS元素操做
#####################################################
JS元素值輸入:
ele = b.find_element_by_xxxx()
b.execute_script("arguments[0].value='admin';",ele)
 
JS點擊元素:
ele = b.find_element_by_xxxx()
b.execute_script('arguments[0].click()', ele)
 
JS去除元素屬性:
ele = b.find_element_by_xxxx()
b.execute_script('arguments[0].removeAttribute("readonly");', ele)
ele.send_keys('test')
 
JS處理滾動條:
target = driver.find_element_by_xxxx()
driver.execute_script("arguments[0].scrollIntoView();", target)


b = webdriver.Chrome()
b.implicitly_wait(30)
b.get('file:///E:/ZM20190316/2.Selenium/TestDemo/uploadFileDemo/uploadFileDemo.html')
b.maximize_window()

ipt_value = b.find_element_by_id('f')
b.execute_script('arguments[0].removeAttribute("readonly");', ipt_value)

ipt_value.clear()
ipt_value.send_keys('abcd')

sleep(3)
b.quit()
相關文章
相關標籤/搜索