0

I am automating a web application, when i call element from browser using javascript classname i get the following:

enter image description here

Then I access the text of the first element at position 0:

enter image description here

but when i try to automate this process with selenium java i get the error "Index 0 out of bounds for length 0" my code is the following

String pattern_2 = driver.findElements(By.className("static-links__link fx-typography-meta js-header-link-service")).get(0).getText();

please help me! :c

1

1 Answer 1

1

In your code the findElements method finds no elements matching the passed locator.
First of all, I see you passing multiple class names with By.className while this method receives a single class name value. To use multiple class names you can use CSS Selector or XPath.
So, try this:

String pattern_2 = driver.findElements(By.cssSelector(".static-links__link.fx-typography-meta.js-header-link-service")).get(0).getText();

I can't be sure this will work since I can't see all your code, but at least the locator now mathces the method.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I used cssSelector copying the selector instead of the class name and it found it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.