Перейти к содержимому

Фотография

Не работает метод selectByVisibleText для выпадающего списка

selenium java автотесты

  • Авторизуйтесь для ответа в теме
Сообщений в теме: 3

#1 Catchermax

Catchermax

    Новый участник

  • Members
  • Pip
  • 30 сообщений
  • ФИО:Максим

Отправлено 09 января 2018 - 15:31

Всем привет, пытаюсь раскурить селениум автоматизируя регистрацию на mail.ru и столкнулся с проблемой что у меня не выбирает из раскрывающего списка дату рождения (день).

junit 4.12, selenium-java 3.8.1

В RegistrationFormPage.java создаю элемент

@FindBy (className = "b-date__day")
private WebElement dayBirthdayDropDownList; //Выпадающий список день рождения

И добавляю ему метод

public void selectDayBirthdayDropDownList(String text){
Select select = new Select (dayBirthdayDropDownList);
select.selectByVisibleText(text);
}

В самом классе теста выполняю метод:

@Test
public void registrationTest(){
indexPage.clickRegistrationButton();
registrationFormPage.inputFirstNameField("Иван");
registrationFormPage.inputLastNameField("Иванов");
registrationFormPage.selectDayBirthdayDropDownList("2");
}

После чего система заполняет поля Имя и Фамилия, но в раскрывающем списке не выбирает значение.

 

Вот что выдает консоль

Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 18864
Only local connections are allowed.
янв 09, 2018 6:24:42 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS


org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "div"
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'CHINATOWN', ip: '172.18.73.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_152'
Driver info: driver.version: unknown


at org.openqa.selenium.support.ui.Select.<init>(Select.java:47)
at com.gmail.frovmxim1.pages.RegistrationFormPage.selectDayBirthdayDropDownList(RegistrationFormPage.java:70)
at com.gmail.frovmxim1.tests.RegistrationTest.registrationTest(RegistrationTest.java:34)
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:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

В чём может быть проблема, где я ошибся?

 


  • 0

#2 Lzk

Lzk

    Специалист

  • Members
  • PipPipPipPipPip
  • 504 сообщений
  • ФИО:Олег
  • Город:Мск

Отправлено 09 января 2018 - 15:43

проблема в том что у тебя , видимо, кастомный селектбокс, который сделан не через тег select, а через div(блок). Открывать его и выбирать значение кликами.

click();

  • 1

#3 Catchermax

Catchermax

    Новый участник

  • Members
  • Pip
  • 30 сообщений
  • ФИО:Максим

Отправлено 10 января 2018 - 07:02

Спасибо за ответ, да, видимо только костылить через click (


  • 0

#4 user12

user12

    Специалист

  • Members
  • PipPipPipPipPip
  • 894 сообщений
  • ФИО:Виктор
  • Город:Минск


Отправлено 10 января 2018 - 11:01

Спасибо за ответ, да, видимо только костылить через click (

 

это не костылить, сейчас много селектов через div

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


  • 0



Темы с аналогичным тегами selenium, java, автотесты

Количество пользователей, читающих эту тему: 0

0 пользователей, 0 гостей, 0 анонимных