Есть отличная удаленная работа для php+codeception+jenkins+allure+docker спецов. 100% remote! Присоединиться к проекту

Не получается с помощью Chromedriver заполнить поле ввода пароля

selenium
webdriver
java
chrome
Теги: #<Tag:0x00007f7b642643c8> #<Tag:0x00007f7b64264288> #<Tag:0x00007f7b64264148> #<Tag:0x00007f7b64264008>

(Onifent) #1

День добрый, у меня возникли некоторые недопонимания между моими тестами и Chromedriver

При попытке заполнить поле ввода пароля, вебдрайвер возвращает следующий эксепшен
WebDriverException: unknown error: cannot focus element

Полный стектрейс:

WebDriverException: unknown error: cannot focus element
  (Session info: chrome=45.0.2454.101)
  (Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 86 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Moscow', ip: '10.8.4.60', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Users\VLADIS~1\AppData\Local\Temp\scoped_dir7716_6045}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=45.0.2454.101, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: b380c7f62a55727c0ec1bcbe581fdf28
Command duration or timeout: 600 milliseconds
Build info: version: '2.47.2', revision: '4d972c01cab1304452627f837654326a11eb92fe', time: '2015-09-24 09:17:17'
System info: host: 'Moscow', ip: '10.8.4.60', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Users\VLADIS~1\AppData\Local\Temp\scoped_dir7716_6045}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=45.0.2454.101, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, webdriver.remote.sessionid=efad18c1-9df0-4a93-9cce-3d0ded614fe1, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: efad18c1-9df0-4a93-9cce-3d0ded614fe1
org.openqa.selenium.WebDriverException: unknown error: cannot focus element
  (Session info: chrome=45.0.2454.101)
  (Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 86 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Moscow', ip: '10.8.4.60', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Users\VLADIS~1\AppData\Local\Temp\scoped_dir7716_6045}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=45.0.2454.101, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: b380c7f62a55727c0ec1bcbe581fdf28
Command duration or timeout: 600 milliseconds
Build info: version: '2.47.2', revision: '4d972c01cab1304452627f837654326a11eb92fe', time: '2015-09-24 09:17:17'
System info: host: 'Moscow', ip: '10.8.4.60', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Users\VLADIS~1\AppData\Local\Temp\scoped_dir7716_6045}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=45.0.2454.101, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, webdriver.remote.sessionid=efad18c1-9df0-4a93-9cce-3d0ded614fe1, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: efad18c1-9df0-4a93-9cce-3d0ded614fe1
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
	at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:273)
	at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:94)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at ru.yandex.qatools.htmlelements.loader.decorator.proxyhandlers.WebElementNamedProxyHandler.invoke(WebElementNamedProxyHandler.java:36)
	at com.sun.proxy.$Proxy12.sendKeys(Unknown Source)
	at elements.RegisterForm.fillFirstPass(RegisterForm.java:73)
	at pages.ProfilePage.registerUser(ProfilePage.java:75)
	at profile.ProfileFormPositiveCases.changeEmailToAnotherExistsEmail(ProfileFormPositiveCases.java:35)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '2.47.2', revision: '4d972c01cab1304452627f837654326a11eb92fe', time: '2015-09-24 09:17:17'
System info: host: 'Moscow', ip: '10.8.4.60', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: driver.version: RemoteWebDriver
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:138)
	... 25 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: cannot focus element
  (Session info: chrome=45.0.2454.101)
  (Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 86 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Moscow', ip: '10.8.4.60', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=C:\Users\VLADIS~1\AppData\Local\Temp\scoped_dir7716_6045}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=45.0.2454.101, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: b380c7f62a55727c0ec1bcbe581fdf28
Build info: version: '2.47.2', revision: '4d972c01cab1304452627f837654326a11eb92fe', time: '2015-09-24 09:17:17'
System info: host: 'Moscow', ip: '10.8.4.60', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: driver.version: RemoteWebDriver
	at sun.reflect.GeneratedConstructorAccessor22.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
	at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:273)
	at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:94)
	at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement$1.invoke(EventFiringWebDriver.java:332)
	at com.sun.proxy.$Proxy2.sendKeys(Unknown Source)
	at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.sendKeys(EventFiringWebDriver.java:355)
	at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.openqa.selenium.remote.server.KnownElements$1.invoke(KnownElements.java:64)
	at com.sun.proxy.$Proxy3.sendKeys(Unknown Source)
	at org.openqa.selenium.remote.server.handler.SendKeys.call(SendKeys.java:50)
	at org.openqa.selenium.remote.server.handler.SendKeys.call(SendKeys.java:1)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

мой pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>madnet-ui</groupId>
    <artifactId>madnet-ui</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <allure.version>1.4.11</allure.version>
        <aspectj.version>1.8.5</aspectj.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.46.0</version>
        </dependency>

        <dependency>
            <groupId>ru.yandex.qatools.htmlelements</groupId>
            <artifactId>htmlelements-all</artifactId>
            <version>1.14</version>
        </dependency>
        <dependency>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-testng-adaptor</artifactId>
            <version>${allure.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>2.46.0</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>2.46.0</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>2.46.0</version>
        </dependency>

        <dependency>
            <groupId>com.github.detro.ghostdriver</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.0.4</version>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>ru.yandex.qatools.ashot</groupId>
            <artifactId>ashot</artifactId>
            <version>1.4.12</version>
        </dependency>

        <dependency>
            <groupId>org.fluttercode.datafactory</groupId>
            <artifactId>datafactory</artifactId>
            <version>0.8</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>ru.yandex.qatools.matchers</groupId>
            <artifactId>webdriver-matchers</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>ru.yandex.qatools.matchers</groupId>
            <artifactId>matcher-decorators</artifactId>
            <version>1.1</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>tests.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <testFailureIgnore>true</testFailureIgnore>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                    <systemPropertyVariables>
                        <!--<driverType>r.firefox</driverType>-->
                        <driverType>r.chrome</driverType>
                        <remoteUrl>http://vradchenko.dev.madnet.ru/</remoteUrl>
                        <serverUrl>http://127.0.0.1:4444/wd/hub</serverUrl>
                        <!--<serverUrl>http://virt4-hetz-hv2.madnet.ru:4444/wd/hub</serverUrl>-->
                    </systemPropertyVariables>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <excludeDefaults>true</excludeDefaults>
        <plugins>
            <plugin>
                <groupId>ru.yandex.qatools.allure</groupId>
                <artifactId>allure-maven-plugin</artifactId>
                <version>2.0</version>
            </plugin>
        </plugins>
    </reporting>

</project>

пример теста который не работает

@Test
    @Stories("Корректный email, несовпадающие пароли")
    public void correctEmailDifferentPasses() {
        page.openPage("register");
        page.registerForm.fillEmailField("test@test.test");
        page.registerForm.fillFirstPassField("1234");
        page.registerForm.fillSecondPassField("12345");
        page.registerForm.clickRegisterButton();
        page.assertPassValidationError("Пароли не совпадают.");
    }

методы fillEmailField, fillFirstPassField и fillSecondPassField выглядят так

 @Step
    public void fillEmailField(String email) {
        utils.sendKeysToElement(emailField, email);
    }

    @Step
    public void fillFirstPassField(String pass) {
        utils.sendKeysToElement(firstPassField, pass);
    }

    @Step
    public void fillSecondPassField(String pass) {
        utils.sendKeysToElement(secondPassField, pass);
    }

метод sendKeysToElement

public void sendKeysToElement(WebElement element, String text) {
        element.click();
        element.sendKeys(text);
    }

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

сама форма которую пытаюсь автоматизировать

<form action="/ru/register/" method="POST" class="form-horizontal" novalidate="novalidate" xmlns="http://www.w3.org/1999/html">
    <fieldset>
            <div class="well">
                  <div class="control-group" id="usertype_group">
            <label class="required control-label">Выберите роль</label>
              <div class="controls">
                  <div id="fos_user_registration_form_registerRole" class="ca-radios radio-element">
    <input type="radio" id="fos_user_registration_form_registerRole_0" name="fos_user_registration_form[registerRole]" required="required" value="publisher" checked="checked"><label for="fos_user_registration_form_registerRole_0" class=""></label><label for="fos_user_registration_form_registerRole_0" class="required">Издатель</label><input type="radio" id="fos_user_registration_form_registerRole_1" name="fos_user_registration_form[registerRole]" required="required" value="freeAdvertiser"><label for="fos_user_registration_form_registerRole_1" class=""></label><label for="fos_user_registration_form_registerRole_1" class="required">Рекламодатель</label>    </div><span class="help-inline"></span>

                  <p class="help-block">
                     
                  </p>
              </div>
          </div>
          <script>
           window.onload = function(){ $.fn.radio && $('#fos_user_registration_form_registerRole').radio(); };
          </script>
                <div class="control-group " id="email_group">
          <label class="required control-label">Email</label>
            <div class="controls">
                <input type="text" id="fos_user_registration_form_email" name="fos_user_registration_form[email]" value="" class="input-xlarge">

                <span class="help-inline"></span>

                <p class="help-block">
                    
                    Обязательное поле.
                </p>
            </div>
        </div>
        <div class="control-group " id="password_group">
          <label for="fos_user_registration_form_plainPassword_first" class="required control-label">
              Пароль</label>
            <div class="controls">
                <input type="password" class="input-medium" name="fos_user_registration_form[plainPassword][first]" id="fos_user_registration_form_plainPassword_first">
                <span class="help-inline"></span>

                <p class="help-block">
                                            Минимальная длина пароля – четыре символа.
                                    </p>
            </div>
        </div>
        <div class="control-group " id="password_confirm_group">
          <label for="fos_user_registration_form_plainPassword_second" class="required control-label">Подтвердите пароль</label>
            <div class="controls">
                <input type="password" class="input-medium" name="fos_user_registration_form[plainPassword][second]" id="fos_user_registration_form_plainPassword_second">
                <span class="help-inline"></span>
                <p class="help-block">
                    
                </p>
            </div>
        </div>
    </div>

        <div class="control-group">
            <div class="controls">
              <button class="btn btn-success app-form-save submit pull-right" type="submit">
                <i class="icon-ok icon-white"></i><i class="icon- loading-white"></i>
                Регистрация
              </button>
            </div>
        </div>


        <input type="hidden" id="fos_user_registration_form__token" name="fos_user_registration_form[_token]" value="244e1dce1ceb246cea9c5ba1237d9ce6f27e9da6">
    </fieldset>
</form>

(Onifent) #2

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

@Test
    @Stories("Корректный email, несовпадающие пароли")
    public void correctEmailDifferentPasses() {
        page.openPage("register");
        page.registerForm.fillEmailField("test@test.test");
        page.registerForm.isVisible();
        page.registerForm.fillFirstPassField("1234");
        page.registerForm.fillSecondPassField("12345");
        page.registerForm.clickRegisterButton();
        page.assertPassValidationError("Пароли не совпадают.");
    }
@Step
    public void isVisible(){
        firstPassField.isDisplayed();
        secondPassField.isDisplayed();
    }

(Onifent) #3

Поменял локаторы на xpath вместо id
оно нормально заработало


(Taras) #4
public void typeTextToTextBox(WebElement element, String text) {
	execScript("arguments[0].setAttribute('value','" + text + "');",
			element);
}