0

So I have been trying to locate the username input box on python using selenium. I have tried xpath, id, class name, etc.

I am also aware of explicit wait for the elements to load. However, depite all this, no luck. I checked to see if the element is in an iframe that I overlooked, but I couldn't find it.

Here is the user input box element.

<div class="panel-body">
                    <h1 class="text-normal" role="banner">Sign in to your account</h1>


                    <form action="/idp/profile/SAML2/Redirect/SSO?execution=e1s1" method="post">
                        <legend>
Login to Qualtrics - co1
                        </legend>
                                        
                        <div class="form-group">
                          <label for="username" class="hidden">Username</label>
                          <div class="input-group">
                            <input id="username" name="j_username" type="text" class="form-control" tabindex="0" placeholder="Username" autocorrect="off" autocapitalize="none" spellcheck="false" aria-label="Username">
                            <div class="input-group-addon">@manhattan.edu</div>
                          </div>
                        </div>
                        <div class="form-group">
                          <label for="password" class="hidden">Password</label>
                          <input id="password" value="" name="j_password" type="password" class="form-control" placeholder="Password" aria-label="Password" autocomplete="off">
                        </div>                         


                                                  <div class="form-element-wrapper">
                            <input type="checkbox" name="donotcache" value="1" id="donotcache">
                            <label for="donotcache">Don't Remember Login</label>
                          </div>

                      <div class="form-element-wrapper">
                        <input id="_shib_idp_revokeConsent" type="checkbox" name="_shib_idp_revokeConsent" value="true">
                        <label for="_shib_idp_revokeConsent">Clear prior granting of permission for release of your information to this service.</label>
                      </div>

                        <div class="form-element-wrapper">
                          <button class="btn btn-default" type="submit" name="_eventId_proceed" onclick="this.childNodes[0].nodeValue='Logging in, please wait...'">Login</button>
                        </div>

                      <div class="clearfix"></div>
                    </form>
                    
                      <img src="https://s.qualtrics.com/login/static/xm_logo-16.png" alt="Qualtrics - co1">
                    <hr>
                    <ul class="create-account">
                        <li><a href="https://start.manhattan.edu/"> Forgot your password?</a></li>
                      <li>New student? <a href="https://start.manhattan.edu/">Get your JasperNet ID and password.</a></li>
                      <li><a href="https://inside.manhattan.edu/offices/its/client-services-hours-and-support.php"> Need Help?</a></li>
                    </ul>
                    </div>

Here is the code that I wrote up to locate the element.

WebDriverWait(browser,10).until(EC.presence_of_element_located((By.XPATH, '/html/body/div/div/div/div/div[3]/div[1]/div[1]/div/ul/li[1]/a')))
browser.find_element_by_xpath('/html/body/div/div/div/div/div[3]/div[1]/div[1]/div/ul/li[1]/a').send_keys("test")

4 Answers 4

0

You are using an absolute xpath which is not advisable. You can use link text or partial link text. You can refer to this tutorial . You can also try using xpath with this locator "//*[contains(text(),'Forgot your password')]"

Sign up to request clarification or add additional context in comments.

Comments

0

Your xpath can be simply:

"//input[id='username']"

elem=WebDriverWait(browser,10).until(EC.presence_of_element_located((By.XPATH, "//input[@id='username']")))
elem.send_keys("test")

You could use try and catches to test if it's present.

Comments

0

I think, in your case, id or xpaht is great to locate the username input box.

browser.find_element_by_xpath("//input[@id='username']").send_keys("test")

So, if you still fail, please provide more information, such as running error log

3 Comments

Thanks for replying. Yah I have tried to use XPath many times. For some reason, the program can't locate the input box. Here is the error log. selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[id='username']"}
@Noktt Note that there is a @ in front of id in the xpath expression.
Hi, @Noktt, if this is the solution to your problem, please Accept the answer or Vote up it :)
0

To send a character sequence to the element instead of presence_of_element_located() you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.form-control#username"))).send_keys("test")
    
  • Using XPATH:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='form-control' and @id='username']"))).send_keys("test")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

1 Comment

I have tested your method and the program returned me with a time out error both times. Is it possible that the input box element is in a hidden frame?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.