I want to select the Code 128 (standard) from select menu, but whatever i did, i could not manage to select any option from the menu.
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");
And I got this response:
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'
Though the <option>
with text Code 128 (standard) is within the html-select tag but the <select>
tag contains the attribute style="display: none;"
:
<select style="color: rgb(0, 0, 0); display: none;" id="code_selector">
Hence Selenium won't be able to interact with it.
To click on the element with text with text Code 128 (standard) you need to Mouse Hover the parent element and then click on the <button>
with text Create Barcode and you can use the following locator strategies:
Code Block:
driver.get("https://www.barcode-generator.org/");
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.iubenda-cs-close-btn"))).click();
new Actions(driver).moveToElement(new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("figure#code_figure_20")))).build().perform();
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='create-overlay']//div[@class='inner-cell']//button[@data-choose='20' and contains(., 'Create Barcode')]"))).click();
Browser Snapshot: