Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98711

Selenium Drop Down

$
0
0

I am trying to learn Selenium. For my small project, I am trying to automate amazon shopping cart. My flow is simple:

  1. Open amazon.com
  2. Search a product
  3. Select size
  4. Add to cart.

I am getting an error on Select Size.

@Test(priority = 3, groups = {"Startshopping"})    public <T> void addItemToCart() throws InterruptedException {        System.out.println("::::addItemToCart");        // Navigate to the product page        driver.get("https://www.amazon.com/Speedo-Rubber-Swim-X-Small-Yellow/dp/B005FYF9MU/ref=sr_1_5?crid=3720YVMBX45Q6&dib=eyJ2IjoiMSJ9.y9eXnqIydahqg0WjO3ehKHM65sn9kbsKPyhIxHga-HIlCuf7zQlZnqY6FxkBOW7DL-5MpTHyDd2qZEbexu2biaX6rOlb_zQC_HxBog7hE2w2B56sqg9S6lNjLhjvhiqoT-5hhn0sxvw6o7wFIW0gtEOd1tLKD7LyYtOjyiLY0CsKpF6mP0Xzwng1s1tF5N32s2XNby9LFVRfDXwCdcv8o-8YghwuEPzTiUzxfMZ8Nrr5vMxNBKGHR2pjgVJL1mJSrPz7WKaVkrRDFrzNGbKlUA7xM-fB1IDnRFHcGIuTzFU.nxFQ-aNfenY6irxxGenpBoDDaUxwWQLI3DDwCnItVrk&dib_tag=se&keywords=swimming%2Bfins%2Bxs&qid=1724391120&sprefix=%2Caps%2C73&sr=8-5&th=1");        //dp = driver.findElement(By.id("wpj3eu-brkvgc-dqr1de-o8f8rv"));        WebElement dp = new WebDriverWait(driver, Duration.ofSeconds(10))                .until(ExpectedConditions.elementToBeClickable(By.id("dropdown_selected_size_name")));            // Perform actions on the element        dp.click();        Select select= new Select(dp);        //select.selectByIndex(3);        //driver.findElement(By.id("add-to-cart-button")).click();    }
PASSED: com.seleniumframework.Amazonshopping.navigateToAmazonPASSED: com.seleniumframework.Amazonshopping.searchItemFAILED: com.seleniumframework.Amazonshopping.addItemToCartorg.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "SPAN"Build info: version: '4.22.0', revision: 'c5f3146703*'

Any pointers?

I expect my code should select the drop down and select one of the options.


Viewing all articles
Browse latest Browse all 98711

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>