pythonselenium浮动框_selenium WebDriver 获取浮动框内容并点击

如何获取在Ajax方式产生的浮动框中的元素

package cn.gloryroad;

import org.testng.annotations.Test;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.AfterMethod;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebDriver.Navigation;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.ie.InternetExplorerDriver;

import java.util.List;

import java.util.concurrent.TimeUnit;

import org.junit.Assert;

public class FirstTestNGDemo {

public WebDriver driver;

String baseUrl = "http://www.baidu.com/";

@Test

public void f() {

Navigation navigation = driver.navigate();

navigation.to("https://www.hao123.com");

//进行一次搜索

WebElement search = driver.findElement(By.xpath("//*[@id='search']/div[3]/form/div[1]/div/input"));

search.sendKeys("我");

try {

Thread.sleep(3000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

search.click();

//存储浮动框中的所有选项

ListsuggetionOptions = driver.findElements(By.xpath("//*[@id='search']/div[3]/form/div[1]/div/div/ul/li"));

for(WebElement element:suggetionOptions){

if(element.getText().contains("我是证人")){

System.out.print(element.getText());

element.click();

try {

Thread.sleep(5000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

break;

}

}

}

@BeforeMethod

public void beforeMethod() {

System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");

driver = new InternetExplorerDriver();

}

@AfterMethod

public void afterMethod() {

driver.quit();

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值