zoukankan      html  css  js  c++  java
  • 在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()
  • 相关阅读:
    RMAN备份脚本执行遇到RMAN-03002,06091问题处理
    物化视图日志过大,手工清理
    大表添加一个字段需求
    oracle_job进程相关学习测试
    11.2.0.4单实例静默安装
    RMAN执行crosscheck archive报错ORA-19633问题处理
    df执行hang住
    应用人员反馈报错,ORA-03137: TTC protocol internal error : [12333]
    普通表分区改造_rename方式
    SQL查询oracle数据库最近备份情况
  • 原文地址:https://www.cnblogs.com/sleeping-cat/p/8118002.html
Copyright © 2011-2022 走看看