• 在Ajax方式产生的浮动框中,点击选项包含某个关键字的选项


    #!usr/bin/env python  
    #-*- coding:utf-8 -*-  
    """ 
    @author:   sleeping_cat
    @Contact : zwy24zwy@163.com 
    """ 
    
    #在Ajax方式产生的浮动框中,点击选项包含某个关键字的选项
    #通过模拟键盘下箭头进行选择悬浮框选项
    
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import unittest
    import time
    
    class TestDemo(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Chrome()
    
        def test_AjaxDivOptionByKeys(self):
            url = 'http://www.sogou.com/'
            self.driver.get(url)
            searchBox = self.driver.find_element_by_id('query')
            searchBox.send_keys('光荣之路')
            time.sleep(2)
            for i in range(3):#选择悬浮窗中第几个联想关键词选项就循环几次
                searchBox.send_keys(Keys.DOWN)#模拟键盘向下箭头
                time.sleep(0.5)
            searchBox.send_keys(Keys.ENTER)
            time.sleep(3)
    
        def tearDown(self):
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
    #!usr/bin/env python  
    #-*- coding:utf-8 -*-  
    """ 
    @author:   sleeping_cat
    @Contact : zwy24zwy@163.com 
    """
    #在Ajax方式产生的浮动框中,点击选项包含某个关键字的选项
    #通过匹配模糊内容选择悬浮框中选项
    
    from selenium import webdriver
    from selenium.common.exceptions import NoSuchElementException
    import traceback
    import time
    import unittest
    
    class TestDemo(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Chrome()
    
        def test_AjaxDivOptionByKeys(self):
            url = 'http://www.sogou.com/'
            self.driver.get(url)
            try:
                searchBox = self.driver.find_element_by_id('query')
                searchBox.send_keys('光荣之路')
                time.sleep(2)
                suggetion_option = self.driver.find_element_by_xpath('//ul/li[contains(.,"免费观看")]')
                suggetion_option.click()
                time.sleep(2)
            except NoSuchElementException as e:
                print(traceback.print_exc())
    
        def tearDown(self):
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    wpf 用c#代码给img指定uri
    c 指针作为出参
    wpf获得系统毫秒数
    绑定元素的长宽(Canvas的子类自动伸展)
    PB与COM之关于创建COM,MTS, and COM+组件(1)
    ASA破解密码
    遭遇奸商(显卡篇)
    “启动Word时提示出错,只能用安全模式才能打开”的解决方法
    PowerSocket对象与HostName
    制做集成SATA驱动的XP安装盘
  • 原文地址:https://www.cnblogs.com/sleeping-cat/p/8118002.html
Copyright © 2020-2023  润新知