课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Finding multiple elements

Finding multiple elements

- [Instructor] Sometimes you'll need to locate multiple elements at once. For example, if we wanted to get all of the radio buttons on the page, we can do so by using a strategy that will return multiple matching elements. Looking at these radio buttons, they all have a tag name of input, but other elements do as well. So simply querying by tag name isn't narrow enough. Looking closer, all of the radio buttons also have a type attribute set to radio. So we can use the CSS selector strategy to locate elements with tag name input and a type attribute of radio. We can test this right here in the browser. You can do control or command F to open the search. And then you're going to type in input and in brackets, type equals radio. And notice here that there's six matches. So now we know that we can give this selector to WebDriver. Let's do that now. Since we want more than one element, we'll use the find elements method instead of the singular find element. This will return a list of web…

内容