Почему веб-драйвер селена не находит текстовое поле на этом сайте? - PullRequest
0 голосов
/ 31 марта 2019

Что должно произойти, это то, что эти текстовые поля для входа в систему должны быть заполнены, и кнопка входа в систему должна быть нажата (своего рода автоматический вход в систему)

Вот ссылка на веб-страницу: Страница входа в Telekom Email

Вот три метода, которые я использую:

public String exportDriver() throws IOException {
        final InputStream IEDriverStream = getClass().getResourceAsStream("/Driver/IEDriverServer.exe");
        final File ieDriverServer = FileWebOpener.stream2file(IEDriverStream, "IEDriverServer", ".exe");
        System.setProperty("webdriver.ie.driver", ieDriverServer.getAbsolutePath());
        return ieDriverServer.getAbsolutePath();
    }

    public void goToWebsite(String url) {
        driver = new InternetExplorerDriver();
        driver.get(url);
    }

    public void setUsernameAndPassword(String username, String password, int Website) throws InterruptedException {
       try{ new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#user[name='pw_usr']"))).sendKeys(username);
        driver.findElement(By.cssSelector("input#pw_pwd[name='pw_pwd']")).sendKeys(password);
        driver.findElement(By.cssSelector("input.button.standard_button_size.large#pw_submit")).click();
    } catch(Exception e){
           e.printStackTrace();
       }
    }

Это исключение, которое я получаю

Ответы [ 5 ]

1 голос
/ 31 марта 2019

Полагаю, вам сначала необходимо:

  1. щелкнуть по полю имени пользователя.
  2. отправить ключи имени пользователя.
  3. щелкнуть по полю пароля.
  4. отправка ключей пароля.
  5. нажмите кнопку отправки

try-findElement (By.Class ("line_normalized clear родственник"). Click);

это находит класс текстового поля имени пользователя и нажимает на него, если я не ошибаюсь, синтаксис может быть неправильным, но идея та же.То же самое касается поля пароля, найдите имя класса / id поля и щелкните его перед отправкой ключей.

0 голосов
/ 02 апреля 2019

Я протестировал его на C # и получил правильное поведение.Ниже приведен код:

using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using System;

namespace IEWebDriver
{
    class Program
    {
        static void Main(string[] args)
        {
            string username = args.Length > 1 ? args[1] : "test";
            string password = args.Length > 1 ? args[2] : "test";
            IWebDriver driver = new InternetExplorerDriver();
            //IWebDriver driver = new ChromeDriver();

            //Navigate to test URL
            driver.Navigate().GoToUrl("https://accounts.login.idm.telekom.com/idmip?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.return_to=https%3A%2F%2Ftipi.api.t-online.de%2Fsrp-auth%2FoneIdm%2Fverify%3FreturnToUrl%3Dhttps%3A%2F%2Femail.t-online.de%2Fem&openid.realm=https%3A%2F%2Ftipi.api.t-online.de&openid.assoc_handle=S4d53c348-b3f2-49a9-b13e-65ade0af6da4&openid.mode=checkid_setup&openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ext1.mode=fetch_request&openid.ext1.type.attr1=urn%3Atelekom.com%3Aall&openid.ext1.required=attr1&openid.ns.ext2=http%3A%2F%2Fidm.telekom.com%2Fopenid%2Foauth2%2F1.0&openid.ext2.client_id=10LIVESAM30000004901PORTAL00000000000000&openid.ext2.scopes=W3sic2NvcGUiOiJzcGljYSJ9XQ%3D%3D&openid.ns.ext3=http%3A%2F%2Fidm.telekom.com%2Fopenid%2Fext%2F2.0&openid.ext3.logout_endpoint=https%3A%2F%2Ftipi.api.t-online.de%2Fsrp-auth%2FoneIdm%2Flogout&openid.ns.ext4=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fui%2F1.0&openid.ext4.mode=popup");

            try
            {
                new WebDriverWait(driver, new TimeSpan(0, 0, 20, 60)).Until(c => c.FindElement(By.CssSelector("input#user[name='pw_usr']"))).SendKeys(username);
                driver.FindElement(By.CssSelector("input#pw_pwd[name='pw_pwd']")).SendKeys(password);
                driver.FindElement(By.CssSelector("input.button.standard_button_size.large#pw_submit")).Click();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
            //Close the browser
            driver.Quit();
            //driver.Close();

        }
    }
}
0 голосов
/ 31 марта 2019

Когда вы заходите на веб-сайт , изначально вам нужно настроить WebDriverWait , чтобы желаемые элементы были активными , и вы можете использовать любой из следующих Стратегии локатора :

0 голосов
/ 31 марта 2019

Я подозреваю, что ваше приложение слишком медленное. Используйте WebDriverWait для идентификации элемента, а затем Sendkeys операцию.

package pkg1;

import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class testIE {

    public static void main(String[] args) {

        System.setProperty("webdriver.ie.driver", System.getProperty("user.dir") + File.separator + "\\Executables\\IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver();        
        driver.get("https://accounts.login.idm.telekom.com/idmip?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.return_to=https%3A%2F%2Ftipi.api.t-online.de%2Fsrp-auth%2FoneIdm%2Fverify%3FreturnToUrl%3Dhttps%3A%2F%2Femail.t-online.de%2Fem&openid.realm=https%3A%2F%2Ftipi.api.t-online.de&openid.assoc_handle=S4d53c348-b3f2-49a9-b13e-65ade0af6da4&openid.mode=checkid_setup&openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ext1.mode=fetch_request&openid.ext1.type.attr1=urn%3Atelekom.com%3Aall&openid.ext1.required=attr1&openid.ns.ext2=http%3A%2F%2Fidm.telekom.com%2Fopenid%2Foauth2%2F1.0&openid.ext2.client_id=10LIVESAM30000004901PORTAL00000000000000&openid.ext2.scopes=W3sic2NvcGUiOiJzcGljYSJ9XQ%3D%3D&openid.ns.ext3=http%3A%2F%2Fidm.telekom.com%2Fopenid%2Fext%2F2.0&openid.ext3.logout_endpoint=https%3A%2F%2Ftipi.api.t-online.de%2Fsrp-auth%2FoneIdm%2Flogout&openid.ns.ext4=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fui%2F1.0&openid.ext4.mode=popup");
        WebDriverWait wait = new WebDriverWait(driver, 30);
        WebElement user= wait.until(ExpectedConditions.elementToBeClickable(By.id("user")));
        user.sendKeys("user12345@gmail.com");
        WebDriverWait wait1 = new WebDriverWait(driver, 30);
        WebElement pass= wait1.until(ExpectedConditions.elementToBeClickable(By.id("pw_pwd")));
        pass.sendKeys("password");


    }

}

Вывод enter image description here

0 голосов
/ 31 марта 2019

Привет, поскольку вы хотите ввести имя пользователя и это поле ввода, вам нужно найти тег ввода.

вы можете попробовать следующий локатор, чтобы найти область ввода текста и выполнить операцию sendkeys:

driver.findElement(By.xpath("//div[@class='line_normalized clear relative']/input")).sendKeys("username");
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...