Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to Remove Error 'No Such Element Exception' From Below Python Code

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 590
    Answer it

    I am trying to run the following code:
    from selenium import webdriver
    # create a new Firefox session
    driver = webdriver.Firefox(executable_path=r'C:\Program Files\geckodriver.exe')
    # navigate to the application home page
    # get the search textbox
    search_field = driver.find_element_by_name("q")
    # enter search keyword and submit
    # get all the anchor elements which have product names displayed
    # currently on result page using find_elements_by_xpath method
    products = driver.find_elements_by_xpath("//h2[@class=‘productname’]/a")
    # get the number of anchor elements found
    print ("Found" + str(len(products)) + "products:")
    # iterate through each anchor element and print the text that is # name of the product
    for product in products:
    print (product.text)
    # close the browser window


    But, getting the following errors:
    Traceback (most recent call last):
      File "C:/Users/nava.malakar/PycharmProjects/setests/", line 12, in <module>
        search_field = driver.find_element_by_name("q")
      File "C:\Users\nava.malakar\PycharmProjects\setests\venv\lib\site-packages\selenium\webdriver\remote\", line 487, in find_element_by_name
        return self.find_element(by=By.NAME, value=name)
      File "C:\Users\nava.malakar\PycharmProjects\setests\venv\lib\site-packages\selenium\webdriver\remote\", line 955, in find_element
        'value': value})['value']
      File "C:\Users\nava.malakar\PycharmProjects\setests\venv\lib\site-packages\selenium\webdriver\remote\", line 312, in execute
      File "C:\Users\nava.malakar\PycharmProjects\setests\venv\lib\site-packages\selenium\webdriver\remote\", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [name="q"]

    Process finished with exit code 1

     - Updated the geckodriver path in the environment variables also, but still i am getting all these errros and not able to run the program

 0 Answer(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: