0

I am trying to login a webpage using Selenium webdriver in Google Chrome. The input box pop ups for login credentials don't have any ID or class. Inspect element features itself not there when I right click on the input box. When I click F12 and check the elements, the input box is not highlighted which means the input box is not part of html content.

When I load the URL, by default the focus goes to username box. So I wanted to use send_keys but this is not working without elements. Is there any other alternate method to send text to username & password fields?

Below is the code I tried.

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.somewebsite.com/')
time.sleep(15)
action = ActionChains(driver)
action.send_keys('userxxxxx').perform()
action.send_keys(Keys.TAB).perform()
action.send_keys('pwdxxxxx')
action.send_keys(Keys.TAB).perform()
action.send_keys(Keys.ENTER).perform()

Attached the screenshot of right click and elements.

enter image description here

When I execute the above code, no error messages. It steps through the further line of codes.

How can I fix this?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Sakthi
  • 3
  • 5
  • There is no need to ActionChains and perform for Send Keys in python. You can just directly use SendKeys. I also see there are no elements you have located. Then I saw your image, and thought this might of help. [Check This Out - similar SO query](https://stackoverflow.com/questions/11522434/how-to-handle-login-pop-up-window-using-selenium-webdriver) – Anand Gautam Jan 10 '22 at 13:11
  • I removed actionchains and used SendKeys directly. I am getting below error message. 'WebDriver' object has no attribute 'Send_Keys'. Seems send keys can be used on some element not on the driver :( – Sakthi Jan 10 '22 at 13:43
  • driver.get("https://admin:admin@your website url"); this one also didnt work for my URL – Sakthi Jan 10 '22 at 13:47
  • Try this. If it is an alert box, this may work (although the first method should be more reliable) `al = driver.switch_to.alert \n al.send_keys(keysToSend="username" + Keys.TAB + "password") \n al.accept()` The `\n` is added to indicate it's a line break (for you). You have to click Enter at each `\n` (and remove `\n` from code) – Anand Gautam Jan 10 '22 at 13:57
  • Take a look at this https://stackoverflow.com/a/49297014/5226491 – Max Daroshchanka Jan 10 '22 at 14:21
  • Unfortunately, it is not an alert box too. Thanks for your suggestion. will check the above link. – Sakthi Jan 10 '22 at 14:29

0 Answers0