1 Call JavaScript

'''

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()

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容