public static void textControl(WebDriver driver, String name,String txt){ WebElement element = driver.findElement(By.name(name)); element.clear(); element.sendKeys(txt); } public static void loginFeizhu() throws InterruptedException { WebDriver driver = init(); driver.get("https://www.fliggy.com/"); Thread.sleep(1000); driver.findElement(By.xpath("//input[@placeholder="目的地/酒店/景点/签证等"]")).click(); Thread.sleep(1000); driver.findElement(By.xpath("//div[@class="recommend-values"]/span[contains(text(),"机票")and @data-itemindex=0]")).click(); */ textControl(driver,"depCityName", "上海")); textControl(driver,"arrCityName","长沙"); textControl(driver,"depDate","2021-07-10"); driver.findElement(By.cssSelector(".close-btn.delegate-click-381")).click(); Thread.sleep(3000); driver.findElement(By.xpath("//form[@id="J_FlightForm"]//button[text()="搜索"]")).click(); tearDown(driver); }
#导包
from selenium import webdriver
from time import sleep
#创建一个驱动对象
browser = webdriver.Chrome()
#使用谷歌浏览器驱动打开浏览器飞猪网主页
browser.get('https://www.fliggy.com/')
#通过名字定位出发城市填写框
DepCityName = browser.find_element_by_name('depCityName')
#清空出发城市
DepCityName.clean()
#出发城市填入北京
DepCityName.send_keys('北京')
#模拟人休息2秒
time.sleep(2)
#通过名字定位出发时间填写框
DepDate = brower.find_element_by_name('depDate')
#填写框填写2021-7-9
DepDate.send_keys('2021-7-9')
#模拟人休息2秒
time.sleep(3)
#点击关闭日期控件
browser.find_element_by_Xpath('//span[text()='close']').click()
#模拟人休息2秒
time.sleep(2)
#通过名字定位到达城市填写框
ArrCityName = browser.find_element_by_name('arrCityName')
#到达城市填入长沙
ArrCityName.send_keys('长沙')
#模拟人休息2秒
time.sleep(2)
#通过名字定位找到搜索按钮
SearchButtom = browser.find_element_by_Xpath('//form[@id='J_FlightForm']//button')
#点击搜索按钮
SearchButtom.click()
#模拟人休息2秒
time.sleep(2)
browser.quit()
#coding:utf-8
from selenium import webdriver
from time import sleep
browser = webdriver.Chrome()
browser.maximize_window()
browser.get('https://www.baidu.com')
browser.implicitly_wait(5)
browser.find_element_by_xpath('//input[@id="kw"]').send_keys(u'测试派')
browser.find_element_by_xpath('//input[@id="su"]').click()
browser.find_element_by_xpath('//*[@id="3"]/h3/a').click()
handles = browser.window_handles
browser.switch_to.window(handles[1])
browser.find_element_by_xpath('//a[text()="领域"]').click()
sleep(5)
browser.quit()
欢迎来到testingpai.com!
注册 关于