码迷,mamicode.com
首页 > 编程语言 > 详细

selenium手动执行JavaScript语句

时间:2017-07-02 19:41:38      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:cli   dynamic   default   nts   close   执行   link   _id   get   

#coding:utf-8
from selenium import webdriver

def main():
    driver = webdriver.Firefox()
    # 改变网页显示文字
    # 网页源代码:
    # <html>
    # <body>
        # <div id="result"></div>
        # <script>document.getElementById("result").innerText = ‘Hello World‘;</script>
    # </body>
    # </html>
    # driver.get(‘http://example.webscraping.com/places/default/dynamic‘)    
    # what = raw_input(‘what:‘)
    # driver.execute_script("document.getElementById(‘result‘).innerText = ‘%s‘"%what)   
    # input(":")
    
    
    driver.get(http://example.webscraping.com/places/default/search)
    driver.find_element_by_id(search_term).send_keys(.)
    # 将下拉第二个选项改为1000
    driver.execute_script("document.getElementById(‘page_size‘).options[1].text = ‘1000‘")
    driver.find_element_by_id(search).click()
    driver.implicitly_wait(30)
    links = driver.find_elements_by_css_selector(#results a)
    countries = [link.text for link in links]
    # driver.close()
    print countries
    print len(countries)


if __name__ == __main__:
    main()

 

selenium手动执行JavaScript语句

标签:cli   dynamic   default   nts   close   执行   link   _id   get   

原文地址:http://www.cnblogs.com/my8100/p/7106817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!