1 Call JavaScript
2019-06-27 本文已影响0人
初见_0308
'''
set scroll par
js='window.scrollTo(left margin,top margin)'
execute_script(js) :// execute the JavaScript program
put content into textarea
text='input text'
js='var sum=document.getElementById(' textarea's id ');sum.value='"+ text +"';'
driver.execute_script(js)
'''
from selenium import webdriver
from time import sleep
driver=webdriver.Firefox()
driver.get('http://www.baidu.com')
driver.set_window_size(600,600)# appear scroll par of vertical and horizontal
driver.find_element_by_id('kw').send_keys('JavaScript')
driver.find_element_by_id('su').click()
sleep(2)
#set the scroll bar position by JS
js='window.scrollTo(100,450);'
driver.execute_script(js)
sleep(3)
driver.quit()