前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python常用面试题_Python+Selenium 常见面试题整理[通俗易懂]

python常用面试题_Python+Selenium 常见面试题整理[通俗易懂]

作者头像
全栈程序员站长
发布2022-08-31 13:29:42
3000
发布2022-08-31 13:29:42
举报

大家好,又见面了,我是你们的朋友全栈君。

整理加复习

1、记录一下刚刚看到的博客https://www..com/lesleysbw/p/5916022.html中的一小段

fd1ec191b8630f0c2b34e429cdccf08c.jpg
fd1ec191b8630f0c2b34e429cdccf08c.jpg

非常认同

看到一位大神的面试准备,我不想写了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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档