public ChromeDriver() {
this(ChromeDriverService.createDefaultService(), new ChromeOptions());
}
public static final String CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver";
public static void main( String[] args )
{
System.setProperty("webdriver.chrome.driver","D:\test\driver\chromeDriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://testingpai.com/");
}
driver.find_element_by_css_selector("fn__layer fn__layer--big").click()
#导包
from selenium import webdriver
from time import sleep
#创建一个驱动对象
browser = webdriver.Chrome()
#使用谷歌浏览器驱动打开浏览器
browser.get('https://www.baidu.com')
#设置抓取标签等待时间5秒
browser.implicitly_wait(5)
#通过id定位搜索框 填写测试派
browser.find_element_by_id('kw"]').send_keys('测试派')
#browser.find_element_by_xpath//input[@id='kw' and @name='wd']
#通过xpah定位确定键 点击
browser.find_element_by_xpath('//input[@id="su"]').click()
#等待5秒
time.sleep(5)
#下面没网络了 视频看不成了 写不下去了
#通过xpah定位测试派位置点击
browser.find_element_by_xpath('//em[text()="测试派"]').click()
browser.quit()
#coding:utf-8
from selenium import webdriver
from time import sleep
#初始化
browser = webdriver.Chrome()
browser.maximize_window()
browser.get('https://www.fliggy.com/')
browser.implicitly_wait(10)
#输入出发城市
depCity = browser.find_element_by_xpath('//input[@name="depCityName"]')
depCity.clear()
depCity.send_keys(u'昆明')
sleep(1)
#输入到达城市
arrCity = browser.find_element_by_xpath('//input[@name="arrCityName"]')
arrCity.clear()
arrCity.send_keys(u'长沙')
sleep(1)
#输入出发日期
depDate = browser.find_element_by_xpath('//input[@name="depDate"]')
depDate.send_keys('2021-07-10')
#关闭日期控件
browser.find_element_by_xpath('//span[text()="close"]').click()
sleep(2)
#点击搜索按钮
browser.find_element_by_xpath('//form[@id="J_FlightForm"]//button[text()="搜索"]').click()
sleep(5)
#退出
browser.quit()
package cn.com.test;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.chrome.ChromeDriver;
public class findElement {
public static void main(String[] args) {
ChromeDriver driver = new ChromeDriver();
driver.get("http://www.baidu.com");
driver.findElementByXPath("//input[@id='kw' and @name='wd']").sendKeys("测试派");
driver.findElementByCssSelector("#su").click();
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
driver.findElementByXPath("//em[text()=\"测试派\"]/parent::a").click();
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Set<String> winHandels=driver.getWindowHandles();// 得到当前窗口的set集合
List<String> it = new ArrayList<String>(winHandels); // 将set集合存入list对象
driver.switchTo().window(it.get(1));// 切换到弹出的新窗口
driver.findElementById("navLogin").click();
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// 登录
driver.findElementById("nameOrEmail").sendKeys("输入账号");
driver.findElementById("loginPassword").sendKeys("输入密码");
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// 登录
driver.findElementById("loginBtn").click();
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// 点击 ‘领域’标签 /html/body/header/nav/a[2]
driver.findElementByXPath("/html/body/header/nav/a[2]").click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.quit();
}
}
欢迎来到testingpai.com!
注册 关于