小小自动化

package web;

import java.util.List;
import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class SelectsStudyTest extends TestCase{
	
	WebDriver dr;
	
	@Before
	public void setUP() throws InterruptedException{
		
		//System.setProperty("webdriver.firefox.bin","D:/Program Files/Mozilla Firefox/firefox.exe" );
		dr = new FirefoxDriver();
		dr.get("http://jiaoyou.51.com/chaoy");
		Thread.sleep(3000);
	}
	
	@Test
	public void testPi() throws InterruptedException {
		dr = new FirefoxDriver();
		dr.get("http://jiaoyou.51.com/chaoy");
		Thread.sleep(3000);
		/**
		linktext 方式实现
		dr.findElement(By.linkText("点击打开")).click();
		dr.findElement(By.linkText("2")).click();
		dr.findElement(By.xpath("(//a[contains(text(),'点击打开')])[2]")).click();
		dr.findElement(By.xpath("(//a[contains(text(),'5')])[20]")).click();
		dr.findElement(By.id("search_btn")).click();
		 */
				
		/**
		cssselector方式实现
		dr.findElements(By.cssSelector(".arrow")).get(0).click();
		dr.findElements(By.cssSelector(".arrow")).get(1).click();
		 */
				
		/**select 方式实现,但是没调试成功
		Select selectage1 = new Select(dr.findElement(By.xpath("(//a[contains(text(),'点击打开')])[2]")));
		Select selectage2 = new Select(dr.findElement(By.xpath("(//a[contains(text(),'5')])[20]")));
		selectage1.selectByValue("1");
		selectage2.selectByValue("5");
		 */
		//Xpath方式实现
		dr.findElement(By.xpath("//span[text()='年龄:']/parent::*/div[1]//a[text()='点击打开']")).click();
		dr.findElement(By.xpath("//span[text()='年龄:']/parent::*/div[1]/ul//li[30]/a")).click();

		dr.findElement(By.xpath("//span[text()='年龄:']/parent::*/div[2]//a")).click();
		dr.findElement(By.xpath("//span[text()='年龄:']/parent::*/div[2]/ul//li[40]/a")).click();

		dr.findElement(By.xpath("//span[text()='地区:']/parent::*/div[2]/div/a[text()='点击打开']")).click();
		dr.findElement(By.xpath("//span[text()='地区:']/parent::*/div[1]/ul/li[1]//span")).click();
		dr.findElement(By.xpath("//span[text()='地区:']/parent::*/div[1]/ul[2]/li[1]//span")).click();
		dr.findElement(By.id("search_btn")).click();
		//dr.findElement(By.xpath("//a[text()='查找']")).click();
		Thread.sleep(3000);
		
		//验证查询结果:
		
		By cssSelector = By.cssSelector(".location");
		List<WebElement> findElements = dr.findElements(cssSelector);
		for(WebElement findElement:findElements){
			System.out.println(findElement.getText());
			assertEquals("定位到地址不为合肥的元素","合肥",findElement.getText());
			//assertEquals(findElement.getText(),"合肥");
		}
		
		dr.quit();
	}
}
<img src="https://img-blog.csdn.net/20140807111626411?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hlbnhuMDAx/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chenxn001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值