2

please I'm quite a selenium newbie and I would need help with the following.

I have this simple HTML code:

<button class="_5s5nM yZn2p  ">Log in</button> == $0

I need to find this element using the words "Log in". I tried this code but I get an error message:

test_submit2 = driver.find_element_by_link_text("Log in")

any idea of why it doesn't work? Many thanks

1
  • does't loook like you've incuded any error message...
    – Mark Mayo
    Mar 30, 2021 at 23:46

3 Answers 3

2

Try this below code, this may work in your case:

//button[contains(text(), 'Log in')];

In your code the syntax seems to be incorrect, linkText will also work.

driver.findElement(By.linkText("Log in")):
0

The answer above is correct, i.e.

//button[contains(text(), 'Log in')];

However, one detail you forgot is that this is By.XPath and not By.linkText

0

To maintain the application security, security testing services are used by developers to maintain dynamic nature of locators where the value class="_5s5nM yZn2p " can be changed after some time.

So for your scenario the locator should be static like //button[text()= 'Log in'] and usage should be like driver.findElement(By.xpath("//button[text()= 'Log in']")):

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.