我正在使用 selenium webdriver 自动化应用程序,下面是我的代码,它工作正常
在这里输入代码:
import java. util.concurrent. TimeUnit;
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;
import org.openqa.selenium.JavascriptExecutor;
import com.thoughtworks.selenium.SeleneseTestCase;
public class MonTaxRep1 extends SeleneseTestCase{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get(" URL ");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement un= driver.findElement(By.name("username"));
un.sendKeys("clientremote");
driver.findElement(By.name("password")).sendKeys("12345678");
driver.findElement(By.name("submit")).click();
// find the element and click on signin
// driver.findElement(By.id("loginButton")).click();
driver.findElement(By.xpath("//a/span[contains(text(),'Thailand')]")).click();
driver.findElement(By.linkText("Williams Limited Thailand")).click();
driver.findElement(By.xpath("//map[@id='Map']/area[3]")).click();
driver.findElement(By.cssSelector("a > img")).click();
driver.findElement(By.xpath("//img[@onclick=\"showItem('_self')\"]")).click();
new Select(driver.findElement(By.name("pay_year"))).selectByVisibleText("2010");
new Select(driver.findElement(By.name("pay_month"))).selectByVisibleText("January");
driver.findElement(By.linkText("Monthly Tax Report")).click();
driver.findElement(By.name("g_title")).sendKeys("Test1");
driver.findElement(By.xpath("//input[@value='Download']")).click();
当 selenium 单击下载链接时,会出现一个弹出窗口,其中默认包含两个单选按钮,单击单选按钮以打开选项,现在我需要将该单选按钮切换为另存为选项,然后单击确定按钮。当我单击确定按钮时,pdf 文件应保存在某些特定的本地驱动器中。为此,我使用了以下代码,但它不起作用。
//Before opening pop-up get the main window handle
String mainWindowHandle=driver.getWindowHandle();
//open the pop-up window(i.e click on element which causes open a new window)
driver.findElement(By.xpath("//input[@value='Download']")).click();
//Below code returns all window handles as set
Set s = driver.getWindowHandles();
Iterator ite = s.iterator();
while(ite.hasNext())
{
String popupHandle=ite.next().toString();
if(!popupHandle.contains(mainWindowHandle))
{
driver.switchTo().window(popupHandle);
}
所以请帮我提供代码,我怀疑下载的pdf文件是否可以逐行打开和阅读,是否可以比较其中的一些文本,这可能吗?