A popup will not be selected using Selenium Webdriver in Safari 10 on Mac

In Safari, I need to select an option from the drop-down list. below code works for all browsers except Safari on Mac OS. I am using Safari 10.1.1 with the selenium web driver version 3.3.1. I wrote code in Java. See code below -

webElement = findElement(field);
if (webElement.isDisplayed())
{
  Select select = new Select(webElement);
  select.selectByVisibleText(value);
}
+4
source share
4 answers

You can try this code:

public void jsSelect(WebElement element, int index) {
        JavascriptExecutor executor = (JavascriptExecutor) driver;
        executor.executeScript("arguments[0].selectedIndex=" + index + ";", element);
    }

public void jsSelect(WebElement element, String item) {
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("const textToFind = '" + item + "';" +
            "const dd = arguments[0];" +
            "dd.selectedIndex = [...dd.options].findIndex (option => option.text === textToFind);", element);
}
+1
source

You can check if the code below works in Safari ..

WebElement dropdown = driver.findElement(By.xpath("//select[@id='profileItem_10536']"));
Select sel = new Select(dropdown);
sel.selectByVisibleText("Yes");

If the code doesn’t work in Safari and works in other browsers, let me know ...

Update:

Sierra, ( Apple). Selenium SafariDriver Safari 10.

:

" SafariDriver ". "Safari API WebDriver. Safari 10 OS X El Capitan macOS Sierra, Safari . - Apple". :

" Safaris WebDriver "

, ,

"/USR//safaridriver"

, . https://webkit.org/blog/6900/webdriver-support-in-safari-10/ https://github.com/SeleniumHQ/selenium/issues/3145

, . .

0

Sierra 10,12.6 safari 11.0 , , .

selectByIndex(3) 
selectByValue("value"), 
selectByVisibleText("Yes");

: , .

0

Safari. element.type("") Selenium, Select.

0

Source: https://habr.com/ru/post/1678169/


All Articles