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
    • 619
    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')
    driver.implicitly_wait(30)
    driver.maximize_window()
    # navigate to the application home page
    driver.get("http://demo.magentocommerce.com/")
    # get the search textbox
    search_field = driver.find_element_by_name("q")
    search_field.clear()
    # enter search keyword and submit
    search_field.send_keys("phones")
    search_field.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

    driver.quit()
         

    But, getting the following errors:
    Traceback (most recent call last):
      File "C:/Users/nava.malakar/PycharmProjects/setests/searchproducts.py", 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\webdriver.py", 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\webdriver.py", line 955, in find_element
        'value': value})['value']
      File "C:\Users\nava.malakar\PycharmProjects\setests\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
        self.error_handler.check_response(response)
      File "C:\Users\nava.malakar\PycharmProjects\setests\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", 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
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: