-3

Need help in solving below error :

URL : https://services.gst.gov.in/services/login

username = driver.find_element_by_name("username");
File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 495, in find_element_by_name
    return self.find_element(by=By.NAME, value=name)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 966, in find_element
    'value': value})['value']
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"username"}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
charan teja
  • 1
  • 1
  • 1
  • 1
  • It's not clear what you are trying to do when you get the error. Please post a [Short, Self Contained, Correct (Compilable), Example](http://sscce.org/) and not how to reproduce the issue. The URL you provided does not respond within 30 seconds. You may also want to edit the title to be in the form of a question. – Rangi Keen Jul 23 '18 at 15:51

4 Answers4

1

You need to introduce Javascript using javascript executor. Code you can try out :

Simply change to this :

 driver.execute_script('arguments[0].click();',WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'username'))))
 WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'username'))).send_keys("abc")

Full code would be something like this :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.action_chains import ActionChains
import time

driver   = webdriver.Chrome(executable_path = r'C:/Users/user**/Downloads/chromedriver_win32/chromedriver.exe')
driver.maximize_window()

wait = WebDriverWait(driver,40)

driver.get("https://services.gst.gov.in/services/login") 

driver.execute_script('arguments[0].click();',wait.until(EC.element_to_be_clickable((By.ID, 'username'))))
wait.until(EC.element_to_be_clickable((By.ID, 'username'))).send_keys("abc")
Panos Kalatzantonakis
  • 12,525
  • 8
  • 64
  • 85
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

your have used the element's id value instead of name value in finding an element . Please change the code in any one of the below options

By Using ID :

username = driver.find_element_by_id("username");

By using name:

username = driver.find_element_by_name("user_name");
Subburaj
  • 2,294
  • 3
  • 20
  • 37
0

To identify and send a character sequence to the <input> field marked with text as Username you have to induce WebDriverWait for the desired element to be clickable and then use execute_script() method to send the text as follows:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_argument('disable-infobars')
    driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://services.gst.gov.in/services/login")
    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.form-control.pad-r-0.ng-pristine.ng-empty.ng-invalid.ng-invalid-required.ng-valid-maxlength.ng-touched#username")))
    driver.execute_script("arguments[0].click();", element)
    element.send_keys("charan teja")
    

Browser Snapshot:

GST

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • why do we need `input.form-control.pad-r-0.ng-pristine.ng-empty.ng-invalid.ng-invalid-required.ng-valid-maxlength.ng-touched#username` this css selector , when we have unique ID. – cruisepandey Jul 24 '18 at 10:30
  • @cruisepandey You not adding any value to the community asking the same question again and again over different discussions in short intervals. Neither you are going through the documentation nor you are willing to raise a question. Is there a way StackOverflow volunteers can help you out? – undetected Selenium Jul 24 '18 at 10:39
  • Glad to know that I am not adding anything to community. Can you please share any link in which it is mentioned that we should prefer css selector over id. I just wanna know why would somebody use a long css selector , when they have an easy option to use ID. It does not make any sense to me and the community as well. Rather you should go through the documents first. What's the point of raising the new question for this requirement. – cruisepandey Jul 24 '18 at 10:45
0

I prefer to use find_element_by_xpath since xpath can be easily found in chrome.

Here's how: right click -> inspect -> right click -> Copy -> CopyXpath

browser.find_element_by_xpath(xpath)

Of course, there is a downside. When the website gets updated, finding by xpath should also be updated.

hyukkyulee
  • 1,024
  • 1
  • 12
  • 17