0

在 Webdriver 中运行以下脚本时出现错误。错误消息:此页第 27 行的脚本中出现错误

package Example;

import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

//import org.openqa.selenium.WebElement;
public class Script {

    public static void main(String args[])throws Exception
    {
        WebDriver driver = new InternetExplorerDriver();
        driver.get("https://www.700creditsolution.com");
        driver.manage().window().maximize();
        Set<String> windowids = driver.getWindowHandles();
        Iterator<String> iter= windowids.iterator();
        while(iter.hasNext())
        {
            System.out.println("Main Window ID :"+iter.next());
        }
        driver.findElement(By.id("lgnLogin_UserName")).clear();
        driver.findElement(By.id("lgnLogin_UserName")).sendKeys("skumara4");
        driver.findElement(By.id("lgnLogin_Password")).clear();
        driver.findElement(By.id("lgnLogin_Password")).sendKeys("Test1234");
        driver.findElement(By.id("lgnLogin_LoginButton")).click();
        Thread.sleep(5000L);

        windowids = driver.getWindowHandles();
        iter= windowids.iterator();
        String main_windowID=iter.next();
        String tabbed_windowID=iter.next();
        System.out.println("Popup Window ID :"+main_windowID);
        //switch over to pop-up window
        driver.switchTo().window(tabbed_windowID);
        System.out.println("Pop-up window Title : "+driver.getTitle());
        driver.findElement(By.xpath("//*[@id='BtnClose']")).click();
        Thread.sleep(1000);
        driver.switchTo().window(main_windowID);
        String msg= driver.findElement(By.xpath("//table[@id='lgnLogin']/tbody/tr/td/table/tbody/tr[4]/td")).getText();
        System.out.println(msg);
        Thread.sleep(1000);
        driver.quit();
    }
}

打印弹出窗口标题后出现错误。

4

1 回答 1

0

基于复制粘贴您的代码,我得到您的第 27 行

Thread.sleep(5000L);

显示错误的原因是因为有一个额外的“ L

你可能想要的是

Thread.sleep(5000); # A 5 second wait
于 2012-12-20T21:01:54.473 回答