auto login in cloud using selenium [python]

856 Views Asked by At

I am trying to write a program that allows me to auto login on a cloud service. The fields corrensponding to the username and password in the HTML are:

<div class="formRow">
    <input type="text" name="emailOrUsername" ng-model="emailOrUsername" panono-text-box=
    "{ &quot;placeholder&quot;: &quot;states.account.logIn.emailOrUsername&quot;, &quot;required&quot;: true }
    " panono-focus="" class="ng-pristine ng-valid panonoTextBox ng-touched" placeholder=
    "Email or username *" spellcheck="false"> 
</div>

<div class="formRow">
    <input type="password" name="password" ng-model="password" panono-text-box=
    "{ &quot;placeholder&quot;: &quot;states.account.logIn.password&quot;, &quot;required&quot;: true }
    " class="ng-pristine ng-untouched ng-valid panonoTextBox" placeholder="Password *" spellcheck="false">
</div>

The code I have written is:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

usernameStr = "my_username"
passwordStr = "my_password"

browser = webdriver.Chrome()
browser.get("https://mywebsite.com")

wait = WebDriverWait(browser, 10)
if wait: 
    username = browser.find_element_by_name("emailOrUsername");
    password = browser.find_element_by_name("password")

    username.send_keys(usernameStr)
    username.send_keys(usernameStr)

I get this error message.

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"emailOrUsername"}

1

There are 1 best solutions below

4
On

Looks like you need to find those elements by name instead of by id

username = browser.find_element_by_name("emailOrUsername");
password = browser.find_element_by_name("password")