0

I have the following two buttons on a form I need to test:

 <div class="ef-buttons">

 <button value="next" name="action" type="submit">
  Continue
 </button>

 <button id="modify_button" value="previous" name="action" type="submit">
  Go Back
 </button>

 </div>

I want to click the Continue Button, for which I wrote the next piece of code:

    By chain = new ByChained(By.className("ef-buttons"),(By.xpath("//*[@value='next']")));
    driver.findElement(chain).click();

However, everytime I get the message Cannot locate an element. What am I doing wrong?

1 Answer 1

2

I'd recommend consolidating your By, and just using CSS. It's faster and easier. This is how you'd select your element:

driver.findElement(By.cssSelector("div.ef-buttons button[name='action']")).click();

FYI, it's better practice to use the name attribute over value since name is more unique.

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

2 Comments

The problem is, that both the NEXT and PREVIOUS buttons have the same 'name' attribute. However, changing it to [value='next'] did the trick! Tnx
HA! I didn't even catch that. that's bad design, but i'm glad you figured it out! :)

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.