I'm trying to automate some stuff on the Amazon website. As a part of it I need to go to today's deals and select 'electronics' checkbox and then I need to get all the links present on the page. I'm writing below code:

List<WebElement> allLinks = driver.findElements(By.id("dealTitle"));

But strangely this is capturing only few links at the end of the page and not the other links of the products I'm interested in. All these have the same id, class names. They are not even in different frame. Can someone please help me to proceed?

2 Answers 2


Id of the element should be unique. You cann't able to get list of webelements by using ID as the locator. Try with class name or tag name to identify the elements.


Part of the issue here is that Selenium is expecting only 1 element on a page to match a given ID (as should be the case). So findElements does not support a "By" of "id" -- only findElement does. But this doesn't help in your case, because you're looking to get the whole list of deal titles.

Instead, you need to find an identifier that all of the titles share. Looking at the Today's Deals webpage, it's actually the span element below the a with id="dealTitle" that contains the title itself -- So you could use something like driver.findElements(By.className("a-declarative")), and then get the innerHTML attribute of those spans.

Check out the documentation on locating UI elements for more: https://www.seleniumhq.org/docs/03_webdriver.jsp#locating-ui-elements-webelements

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.