driver.switchTo()方法无法正常工作

时间:2018-10-01 11:00:23

标签: selenium selenium-webdriver automated-tests

下面是我的Selenium代码,在其中我已使用循环执行了该代码,但在第一次迭代后switchTo()window()无法正常工作。控件仅在父窗口中搜索元素。 请帮助我在同一窗口中进行搜索。

for(String Child : d.getWindowHandles())
        {
             d.switchTo().window(Child);
             System.out.println("Title of page is  "+d.getTitle());
        }

        Select dropdown1= new Select(d.findElement(By.xpath("//select[@id='securityGroup']")));
        dropdown1.selectByVisibleText(e.getCellData("Isin", 5,i));
        // wait.until(ExpectedConditions.elementToBeClickable(By.id("securityGroup"))).sendKeys(e.getCellData("Isin",5 ,i));

        wait.until(ExpectedConditions.elementToBeClickable(By.id("firstAttribute"))).sendKeys(e.getCellData("Isin",6 ,i));
        wait.until(ExpectedConditions.elementToBeClickable(By.id("secondAttribute"))).sendKeys(e.getCellData("Isin",7 ,i));
        wait.until(ExpectedConditions.elementToBeClickable(By.id("thirdAttribute"))).sendKeys(e.getCellData("Isin",8 ,i));
        wait.until(ExpectedConditions.elementToBeClickable(By.id("fourthAttribute"))).sendKeys(e.getCellData("Isin",9 ,i));
        Thread.sleep(1000); 
        d.findElement(By.xpath("//input[@id='searchButton']")).click();
        Thread.sleep(1000); 
        d.switchTo().window(parent);
        System.out.println("Title of page is  "+d.getTitle());
        wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@onclick='openGenerateFISN();' and @title='Generate']"))).click(); 
        Thread.sleep(2000); 
         for(String Child1 : d.getWindowHandles())
        {
             d.switchTo().window(Child1);
            System.out.println("Title of page is  "+d.getTitle());
        }

        if(!(e.getCellData("Isin", 10, i).isEmpty()))`enter code here`
        {

0 个答案:

没有答案