0

What is wrong in the below code

import os
import time
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://x.x.x.x/html/load.jsp")
elm1 = driver.find_element_by_link_text("load")
time.sleep(10)
elm1.click()
time.sleep(30)
driver.close()

The page source is

<body>   
<div class="formcenterdiv">
    <form class="form" action="../load" method="post">
      <header class="formheader">Loader</header>
      <div align="center"><button class="formbutton">load</button></div>
    </form>   
</div>


</body></html>

I want to click on button load. when I ran the above code getting this error selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: load

0

2 Answers 2

2

As the documentation says, find_elements_by_link_text only works on a tags:

Use this when you know link text used within an anchor tag. With this strategy, the first element with the link text value matching the location will be returned. If no element has a matching link text attribute, a NoSuchElementException will be raised.

The solution is to use a different selector like find_element_by_class_name:

elm1 = driver.find_element_by_class_name('formbutton')
Sign up to request clarification or add additional context in comments.

Comments

1

Did you try using Xpath?

As the OP said, find_elements_by_link_text works on a tags only: Below code might help you out

driver.get_element_by_xpath("/html/body/div/form/div/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.