Selenium IE webdriver无法点击"登录"链接

时间:2016-11-05 08:10:05

标签: java internet-explorer selenium selenium-webdriver webdriver

我已经编写了以下代码,使用selenium IE webdriver(64位)和IE 11浏览器登录 [" http://www.quikr.com/"] [1] 。但是,selenium IE webdriver无法点击“登录”'链接。你能帮忙吗?

我使用:

IE版本: 11

Selenium版本:版本3.0.1

操作系统: Win10 64位

Java: 1.8

package Selenium_WebDriver_Part1;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Quikr1 {
    public static WebDriver driver=null;
    @Test
    public void loginTest() throws InterruptedException {
        System.setProperty("webdriver.ie.driver", "C:\\Eclipse\\Drivers\\IEDriverServer.exe");
        DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer();
        ieCaps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.quikr.com/");
        ieCaps.setCapability(CapabilityType.BROWSER_NAME, "IE");
        ieCaps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
        ieCaps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
        driver = new InternetExplorerDriver(ieCaps);
        driver.manage().window().maximize();
        Thread.sleep(10000);
        WebDriverWait wait = new WebDriverWait(driver, 10);
                    wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@class='sign-in']"))).click();
        //driver.findElement(By.xpath(".//*[@id='fullnameFromPopUp']")).sendKeys("UserName");
        //driver.findElement(By.xpath(".//*[@id='password']")).sendKeys("Password");
        //driver.findElement(By.xpath(".//*[@class='btn btn-default btn-default-submit btn-lg btn-block login-btn']")).click();
    }       
}

1 个答案:

答案 0 :(得分:0)

您应该始终发布您收到的错误消息。你可能会得到这个

selenium.common.exceptions.NoSuchWindowException: Message: Unable to find element on closed window

这是IE上的常见问题。查看this answer如何解决它。通过此更改,您的代码对我有用。

然而,我在使用IEdriver的页面上获得了非常糟糕的性能。打开登录窗口弹出窗口需要10秒。您可能需要考虑在代码中添加一些等待函数/增加timeout。检查docs或此stackoverflow answer

 driver.findElement(By.cssSelector("span.sign-in")).click();
 // add wait for element / set-up timeout etc
 driver.findElement(By.xpath(".//*[@id='fullnameFromPopUp']")).sendKeys("UserName");