1

Selenium cannot find the element "Log in". I looked through the other stackoverflow questions regarding this and didn't seem to completely resolve.

// C#
IWebElement submit = driver.FindElement(By.Name("Log in"));
submit.Click();

// html
<div class="btn-group pull-right">
<button class="btn btn-success shadow" type="submit">Log in</button>
</div>

2 Answers 2

6

try driver.FindElement(By.XPath("//button[@type='submit'][text()='Log in']")

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

5 Comments

What if later or the rest of the page has more buttons that can submit. That would bring back 1+.
perfect, don't have access to set the name attribute
LULZ, tell your dev's to always provide IDs for there elements so the testers can test. I am a dev I always provide IDs for my testers.
@Cubicle.Jockey You're right about more than one button and th id's. But it's always possible to write more complex locator to make it unique. BTW, this one //button[@type='submit'][text()='Log in'] should work too
@AlexanderPetrovich yep that's cool. I would modify the answer you gave to reflect that.
3

You never set the button name attribute.

<button class="btn btn-success shadow" type="submit" name="Log in">Log in</button>

Comments

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.