码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-12-26 15:19:22      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:免费   键盘   rdo   免费观看   path   包含   unit   int   tom   

 

#!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()

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

标签:免费   键盘   rdo   免费观看   path   包含   unit   int   tom   

原文地址:https://www.cnblogs.com/sleeping-cat/p/8118002.html

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