0

I am at the following site: https://www.ces-us.com/index.asp

and I am using the following code:

    path_to_chromedriver = r'C:\chromedriver'  # change path as needed
    browser = webdriver.Chrome(executable_path=path_to_chromedriver)
    url = 'https://www.ces-us.com/index.asp'
    browser.get(url)

    username = browser.find_element_by_id("username") #error on this statement
    password = browser.find_element_by_id("password")

    username.send_keys("my username")
    password.send_keys("my password")

    browser.find_element_by_name("submit").click()

But for all different find_ functions I get the following error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="username"]"}
  (Session info: chrome=80.0.3987.163)

Even though the HTML looks as following:

div class="col-md-3">
                <div class="widget-item">
                    <div class="request-information">

                        <h4 class="widget-title">Customer Login</h4>
                        <form class="request-info clearfix" method="post" action="_login.asp">
                            <div class="full-row">
                                <label for="username">Username:</label>
                                <input type="text" id="uid" maxlength="15" name="uid">
                            </div> <!-- /.full-row -->

                            <div class="full-row">
                                <label for="password">Password:</label>
                                <input type="password" id="pwd" maxlength="15" name="pwd">
                            </div> <!-- /.full-row -->
Zanam
  • 3,540
  • 9
  • 42
  • 91

1 Answers1

1

Your IDs are incorrect, Try below solution :

wait = WebDriverWait(browser , 10)
browser.get("https://www.ces-us.com/index.asp")
wait.until(EC.presence_of_element_located((By.ID, "uid"))).send_keys("my username")
wait.until(EC.presence_of_element_located((By.ID, "pwd"))).send_keys("my pwd")

wait.until(EC.presence_of_element_located((By.XPATH, "//input[@class='mainBtn pull-left']"))).click()

Note : please add below imports to your solution

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
Dipak Bachhav
  • 3,579
  • 1
  • 5
  • 19