在硒Webriver中选择下拉菜单时有问题

问题描述 投票:2回答:1

我有一个下拉列表的HTML示例源。我尝试了所有可能性,但是我有

“线程“主”中的异常org.openqa.selenium.ElementNotInteractableException:元素不硒网络驱动程序中的“ interactiveable”错误。

Plz,请给我一个解决方案,以在Web驱动程序中选择下拉值。我应该使用什么?[HTML源在这里] [1]

WebElement clickclientdrpdown=driver.findElement(By.xpath("/html/body/div[5]/div[3]/div[1]/div/div[4]/div/form/div[1]/span/span[1]/span/span[1]")); 
clickclientdrpdown.click(); 
WebElement selectclientdrpdown = driver.findElement(By.xpath("/html/body/div[5]/div[3]/div[1]/div/div[4]/div/form/div[1]/span/span[1]/span/span[1]")); 
selectclientdrpdown.sendKeys("1 Private solution"); 
selenium-webdriver
1个回答
2
投票

如果HTML格式发生更改,您的xpath容易被破坏,只需使用findElement(By.Name)name属性就不太可能更改,因为它是Form的一部分,并且name是参数传递给服务器的名称:

//Selenium method  specific, prone to failure if element is disabled or not visible
WebElement selectclientdrpdown = driver.findElement(By.name("companyId"));
selectclientdrpdown.sendKeys("1 Private solution");



//Using the JavascriptExecutor
JavascriptExecutor js = (JavaScriptExecutor)driver;
js.ExecuteScript("document.querySelector("select[name='companyId'].value = '1 Private solution';"); 
© www.soinside.com 2019 - 2024. All rights reserved.