0

I trying to click on the create account button in registration form. this is how the button locate in the html page:

<div id="submitContainer"><button type="submit" class="large"><span><strong> Create Account </strong></span></button></div>

this is the button xpath:

//*[@id="submitContainer"]/button/span/strong

the problem is that the button don't have id, he locate inside a div. I try to use by id,xpath,css,name, but all of this not working:

driver.findElement(By.id("submitContainer")).click();

driver.findElement(By.xpath("//*[@id='submitContainer']/button/span/strong")).click();

driver.findElement(By.tagName("Create Account")).click();

driver.findElement(By.className("large")).click();

thanks!

2
  • this is how the button locate in the html page: <div id="submitContainer"> <button type="submit" class="large"> <span> <strong> Create Account </strong> </span> </button> </div> Commented Aug 29, 2015 at 9:02
  • How about : //*[@id="submitContainer"]/button ? Commented Aug 29, 2015 at 9:05

5 Answers 5

3

In your examples, except for the last one, you are not targeting the button. Now your last example, should actually locate the button-element:

driver.findElement(By.className("large")).click();

Could you please post the error message you are getting?

Are there more than one element on the page with className "large"?

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

1 Comment

I would use a CSS selector to target specifically the button with class large. driver.findElement(By.cssSelector("button.large")).click();
1

Make sure the button is in view window, if it is then try clicking on it. Try to wait for the element to load. There might be an issue with your element being loaded into DOM -

driver.wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//button[@type='submit']"))).click();

Hope this helps.

3 Comments

...or you could just click the button and if it's not enabled or displayed you will get an error anyway without all the extra code checks...
Right @JeffC. I have updated answer with wait() function. I should have thought that before. Thanks :)
The wait.until() will return the element you waited for... just store it and .click() it. No need to search for it again.
0

If you want to use xpath, the correct syntax is //button[@type='submit']

Comments

0

Use this line below:

Thread.sleep(3000);

I got the result once I used this one. Since some time we need to give some sleep time for the site to load fully to pull the Xpath.

2 Comments

I see this as a workaround, not a final solution... there must be a better way than a hard-coded Thread.Sleep...
You can share if you have any better ways than this to make the code more effective
-1

You can use the linkText

driver.findElement(By.linkText("Create Account")).click();

Hope it will work for you.

1 Comment

This won't work because it's not a link, it's a button.

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.