Java – the drop-down list cannot be selected using selenium webdriver on safari browser 10 on Mac
•
Java
In Safari browser, I need to select an option from the drop-down list
webElement = findElement(field); if (webElement.isDisplayed()) { Select select = new Select(webElement); select.selectByVisibleText(value); }
Solution
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); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码