1

Based on the image below the dropdown list option id is id="CountryId" enter image description here

 Select dropdown = new Select(obj.findElement(By.id("CountryId"))); System.out.println(dropdown + "is trigger"); dropdown.selectByVisibleText("Malaysia"); dropdown.selectByValue("52"); 

Based on the snippet above I am keep getting error which could not select the drop down list option

enter image description here

4

2 Answers 2

1

You can try with JS as well :

JavascriptExecutor js=(JavascriptExecutor) driver; js.executeScript("return document.getElementById('CountryId').selectedIndex = '52';"); 

update 1 :

driver.manage().window().maximize(); driver.get("http://demowebshop.tricentis.com/cart"); WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText("BOOKS"))).click(); wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("h2.product-title a"))).click(); wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[id^='add-to-cart-button']"))).click(); wait.until(ExpectedConditions.elementToBeClickable(By.linkText("shopping cart"))).click(); Select select = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("CountryId")))); select.selectByValue("52"); 
5
  • still not working getting session id error
    – Jordan
    CommentedAug 30, 2021 at 11:27
  • Can you share the entire error stack trace ? In text format here ?CommentedAug 30, 2021 at 11:32
  • Session ID: b12dccd3-af5a-b54d-9a47-0a71d2b57631 at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    – Jordan
    CommentedAug 30, 2021 at 11:34
  • See the above updated 1 section, it works fine on my local.CommentedAug 30, 2021 at 11:59
  • 1
    yes thanks it works i think is because i did not add the WebDriverWait wait = new WebDriverWait(driver, 30);
    – Jordan
    CommentedAug 31, 2021 at 6:49
0

Is the page fully loaded when you try to click on that dropdown?

Is that dropdown inside another object and not accesible on its own?

One of those things are happening.

I'd start with

WebDriverWait wait = new WebDriverWait(yourDriver, 10); WebElement select = wait.until(ExpectedConditions.elementToBeClickable(selectFinder))); select.click(); 

If that doesn't work then the select is not accesible on its own and you need to go through its parent items on the HTML until its available. It doesnt make much sense but thats how selenium works.

0

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.