我想从选择菜单中选择代码128(标准),但无论我做了什么,我都无法从菜单中选择任何选项。
WebDriver driver = Driver.get();
driver.manage().window().setPosition(new Point(-1000, 0));
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.barcode-generator.org/");
BrowserUtils.waitFor(2);
driver.findElement(By.className("iubenda-cs-close-btn")).click();
BrowserUtils.waitFor(2);
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement selectElement = driver.findElement(By.xpath("//select[@id='code_selector']"));
Select select = new Select(selectElement);
List<WebElement> options = select.getOptions();
BrowserUtils.waitFor(4);
System.out.println("options.size() = " + options.size());
select.selectByVisibleText("Code 128 (standard)");
driver.findElement(By.id("barcode_data")).sendKeys("abc");
我得到了这样的回应:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 53482
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Haz 18, 2023 1:53:26 ÖS org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
options.size() = 67
org.openqa.selenium.ElementNotInteractableException: element not interactable: Element is not currently visible and may not be manipulated
(Session info: chrome=114.0.5735.134)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
1条答案
按热度按时间egmofgnx1#
虽然带有文本***Code 128(standard)***的
<option>
在html-select标记内,但<select>
标记包含属性style="display: none;"
:因此,Selenium将无法与它互动。
解决方案
要点击元素的文本***Code 128(standard)***,需要Mouse Hover父元素,然后点击
<button>
,文本*Create Barcode,您可以使用以下locator strategies: