zoukankan      html  css  js  c++  java
  • 执行JS

    # -*- coding:utf-8 -*-
    """
    执行 js 脚本
    """
    
    from selenium import webdriver
    import unittest
    
    class login(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()
            self.driver.implicitly_wait(30)
            self.base_url = 'http://www.51testing.com'
            self.verificationErrors = []
            
        def test_loginpass(self):
            driver = self.driver
            driver.get(self.base_url)
            
            js='var q=document.getElementById("username");q.style.border="1px solid red";'
            driver.execute_script(js)
            driver.find_element_by_id('username').send_keys('username')
            driver.find_element_by_id('userpass').send_keys('password')
            driver.find_element_by_id('dologin').click()
            verify = raw_input('输入你看到的验证码,按 Enter 键: ')
            driver.find_element_by_id('xspace-seccode').send_keys(verify)
            driver.find_element_by_id('securitysubmit').click()
            
        def tearDown(self):
            self.driver.quit()
            self.assertEqual([], self.verificationErrors)
            
    if __name__ == '__main__':
        unittest.main()
     1 # -*- coding:utf-8 -*-
     2 """
     3 调用JS代码返回网页的title,并统计超链接的数量
     4 """
     5 
     6 from selenium import webdriver
     7 
     8 driver = webdriver.Firefox()
     9 driver.get("http://www.baidu.com")
    10 title = driver.execute_script("return document.title")
    11 print title
    12 
    13 links = driver.execute_script("var links = document.getElementsByTagName('A'); return links.length")
    14 print links
  • 相关阅读:
    2016.7.22.noip2012D2
    2016.7.21.noip2014D2
    LIS最长上升子序列O(n^2)与O(nlogn)的算法
    vijos1910解方程
    vijos1909寻找道路
    viojs1908无线网路发射器选址
    P1907飞扬的小鸟
    P1906联合权值
    P1905生活大爆炸版 石头剪刀布
    poj1274(匈牙利算法)
  • 原文地址:https://www.cnblogs.com/Roger1227/p/3134759.html
Copyright © 2011-2022 走看看