简体   繁体   English

Selenium IE Webdriver无法单击“登录”链接

[英]Selenium IE webdriver is unable to click on the “Sign In” link

I have written the below code to login to the [" http://www.quikr.com/ "][1] using selenium IE webdriver (64 bit) and IE 11 browser. 我已经编写了以下代码,使用硒IE Web驱动程序(64位)和IE 11浏览器登录到[“ http://www.quikr.com/ ”] [1] But the selenium IE webdriver is unable to click on the 'Sign In' link. 但是硒IE Web驱动程序无法单击“登录”链接。 Could you please help on the same. 您能帮忙吗?

I'm Using: 我正在使用:

IE Version: 11 IE版本: 11

Selenium Version: Version 3.0.1 硒版本: 3.0.1版

OS: Win10 64 bit 操作系统: Win10 64 bit

Java: 1.8 爪哇: 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();
    }       
}

You should always post the error message you are getting. 您应该始终发布收到的错误消息。 You might be getting this 你可能会得到这个

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

This is common problem on the IE. 这是IE上的常见问题。 Check out this answer how to solve it. 看看这个答案如何解决。 With this change, your code is working for me. 进行此更改后,您的代码对我有用。

However I am getting really awful performance on your page with IEdriver. 但是,使用IEdriver在您的页面上获得了非常糟糕的性能。 Opening the login window pop-up takes 10s. 打开登录窗口弹出窗口需要10秒钟。 You might want to consider adding some wait function to your code / increase the timeout . 您可能需要考虑在代码中添加一些等待功能/增加超时时间 Check the docs or this stackoverflow answer . 检查文档或此stackoverflow 答案

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM