python常用面试题_Python+Selenium 常见面试题整理[通俗易懂]
大家好,又见面了,我是你们的朋友全栈君。
整理加复习
1、记录一下刚刚看到的博客https://www..com/lesleysbw/p/5916022.html中的一小段
非常认同
看到一位大神的面试准备,我不想写了TT。等我好好看完,再决定怎么继续写下去吧,照搬毫无意义。大神博客地址:https://www..com/lesleysbw/category/946223.html
Qunar机票搜索场景
访问Qunar机票首页http://flight.qunar.com,选择“单程”,输入出发、到达城市,选择today+7日后的日期,点“搜索”,跳转到机票单程搜索列表页。
好像网上没有找到python实现,简单写了下
from selenium import webdriver
import datetime
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome(r’D:\chromedriver.exe’)
driver.maximize_window()
driver.implicitly_wait(8)
driver.get(“https://flight.qunar.com/”)
single_way = driver.find_element_by_xpath(‘//*[@id=”searchTypeSng”]’)#单程
from_city = driver.find_element_by_xpath(‘//*[@id=”dfsForm”]/div[2]/div[1]/div/input’)#出发城市
to_city = driver.find_element_by_xpath(‘//*[@id=”dfsForm”]/div[2]/div[2]/div/input’)#到达城市
from_date = driver.find_element_by_xpath(‘//*[@id=”fromDate”]’)#出发时间
#选择单程
if (single_way.is_selected()):
pass
else:
single_way.click()
#选择到达城市-上海
action = ActionChains(driver)
action.move_to_element(to_city).click().perform()
driver.find_element_by_xpath(“//div[@data-panel=’domesticto-flight-hotcity-to’]//a[@class=’js-hotcitylist’ and text()=’上海’]”).click()
driver.implicitly_wait(8)
#选择出发城市-北京
action.move_to_element(from_city).click().perform()
driver.find_element_by_xpath(“//div[@data-panel=’domesticfrom-flight-hotcity-from’]//a[@class=’js-hotcitylist’ and text()=’北京’]”).click()
driver.implicitly_wait(8)
#设置出发日期-7天后
date = (datetime.datetime.now() + datetime.timedelta(days=7)).strftime(“%Y-%m-%d”)
# print(date)
from_date.send_keys(Keys.CONTROL + “a”)
# js = “document.getElementById(‘fromDate’).value=’2019-02-07′” #编写JS语句
# driver.execute_script(js) #执行JS
from_date.send_keys(date)
#搜索
driver.find_element_by_xpath(‘//*[@id=”dfsForm”]/div[4]/button’).click()
time.sleep(6)
driver.quit()
执行搜索,会出现一直加载中的情况,不知道为啥,有时候又挺好的
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151439.html原文链接:https://javaforall.cn
相关文章
- Python嵌套函数与匿名函数
- Python 查找算法_众里寻他千百度,蓦然回首那人却在灯火阑珊处(线性、二分,分块、插值查找算法)
- Python基础15-日志模块logging
- Python+Flask实现的学生培养计划管理系统
- 最强最炫的Python数据可视化神器,没有之一!
- 使用 setup.py 将 Python 库打包分发到 PyPI 踩坑指南
- Python进阶41-drf框架(三)
- 【Python秒杀脚本】淘宝或京东等秒杀抢购
- Python-drf前戏38.3-前端Vue03
- Python-drf前戏38.1-前端Vue01
- python 函数、运算符以及运算符优先级
- 8000 字 Python 数据可视化实操指南
- 一对兔子从出生后第三个月起每个月_兔子繁衍问题python
- Python 细聊从暴力(BF)字符串匹配算法到 KMP 算法之间的精妙变化
- Python项目47-前后端分离登录注册页(继续撸)
- 记一次python清洗疫情历史数据
- python线程间通信的方式_android 线程间通信
- 遗传算法做多目标优化_python 遗传算法
- Python自动化办公小程序:实现报表自动化和自动发送到目的邮箱
- python 制作淘宝秒杀脚本