分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

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

发布时间:2023-09-06 01:32责任编辑:林大明关键词:Ajax
#!usr/bin/env python ?#-*- coding:utf-8 -*- ?""" @author: ??sleeping_cat@Contact : zwy24zwy@163.com """ #在Ajax方式产生的浮动框中,点击选项包含某个关键字的选项#通过模拟键盘下箭头进行选择悬浮框选项from selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport unittestimport timeclass 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 webdriverfrom selenium.common.exceptions import NoSuchElementExceptionimport tracebackimport timeimport unittestclass 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方式产生的浮动框中,点击选项包含某个关键字的选项

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved