I'm going to assume that you mean when you select an element, some kind of selector (say By.className("primary") ), and you want to get the next element that has this class name?
To do this, you need to call driver.findElements(By.className("primary")) . This will give you a list of all the elements matching this selector. Then you can choose the one that suits you.
If, however, next () actually returns the next sibling, then you can do this in the following ways:
- Javascript: element.nextSibling ()
- CSS: element + *
- Xpath: element / follow-sibling :: *
(Replace the item with your selector)
source share