zoukankan      html  css  js  c++  java
  • python3.6+selenium_调用JavaScript

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019/1/11 16:36
    # @File : unittest_test9_5.py
    '''
    调用javascript
    '''
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium import webdriver
    import unittest
    import time
    
    class ExecuteJavaScriptTest(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(20)
            self.driver.maximize_window()
            self.driver.get('https://www.cnblogs.com/')
    
        def test_execute_javascript(self):
            program_lan = self.driver.find_element_by_xpath('//li[@id="cate_item_2"]/a')
            program_py = self.driver.find_element_by_xpath('//li/a[@href="/cate/python/"]')
    
            self.highlightElement(program_lan)
            #鼠标先移动到“编程语言”上,然后点击Python
            ActionChains(self.driver).move_to_element(program_lan).click(program_py).perform()
            time.sleep(2)
        def tearDown(self):
            self.driver.quit()
    
        #给元素加上红色边框,2秒后还原
        def highlightElement(self,element):
            self.driver.execute_script("arguments[0].setAttribute('style',arguments[1]);",element,
                              "border:2px solid red;")
            time.sleep(2)
            self.driver.execute_script("arguments[0].setAttribute('style',arguments[1]);", element,
                              "")
    
    if __name__ == "__main__":
        unittest.main(verbosity=2)
  • 相关阅读:
    BZOJ3744 : Gty的妹子序列
    BZOJ2827 : 千山鸟飞绝
    BZOJ3547 : [ONTAK2010]Matchings
    BZOJ1185 : [HNOI2007]最小矩形覆盖
    BZOJ3046 : lagoon
    BZOJ3743 : [Coci2014]Kamp
    BZOJ3742 : Painting
    iOS移动开发周报-第25期
    适合码农工作时玩的游戏:Scrum
    iOS移动开发周报-第24期
  • 原文地址:https://www.cnblogs.com/xiuxiu123456/p/10450692.html
Copyright © 2011-2022 走看看