sendKeys (Keys.DOWN) не перемещается к опции в выпадающем списке с автоматическими подсказками - PullRequest
0 голосов
/ 22 мая 2018

Ocupation Я пытаюсь выбрать вариант из выпадающего списка.Когда я ввожу строку в выпадающий список, sendKeys (keys.down) не переходит к опции.Я получаю сообщение об ошибке "элемент не может сфокусироваться"Я добавил снимки экрана со Aviva Code де и раскрывающийся список на экране.Это код.

JavascriptExecutor jse = (JavascriptExecutor) драйвер;jse.executeScript ("document.getElementById ('proposer.occupation- selectized'). value = 'Composer';");driver.findElement (By.xpath ( "// * [@ ид = 'содержание'] / дела 4 / дела / дела 1 / дела [8] / дела . 2 / дел / дел 1 / DIV ")) SendKeys (Keys.DOWN);. Driver.findElement (By.id ( "proposer.occupation-selectized")) GetText ();String script = "return document.getElementById ('proposer.occupation-selectized'). Value;";

    String text=(String) jse.executeScript(script);
    System.out.println(text);

1 Ответ

0 голосов
/ 23 мая 2018

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

        WebElement Occupation_textbox = driver.findElement(By.id("proposer.occupation-selectized")); //To locate the occupation textbox
    Occupation_textbox.sendKeys("Develop"+Keys.DOWN+"\n"); //To enter the occupation search string and then go one down and select the option --or-- you can add a wait for the dropdown element to be visible and then take the current element and then go down (Keys.down)   "Occupation_textbox.sendKeys(Keys.DOWN+"\n")"; 

    WebElement Occupation_selected_text = driver.findElement(By.xpath(".//*[@id='proposer.occupation-selectized']/preceding-sibling::div")); //Locate element to capture the text of the selected option

    //There are two ways you can take out the value on your page
    String value_way1 = Occupation_selected_text.getAttribute("data-value"); // to take the text from data-value attribute 
    String value_way2 = Occupation_selected_text.getText(); // to get the text in the search field

    System.out.println(value_way1);
    System.out.println(value_way2);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...