0

I am attempting to locate the empty textbox by the input id 'Department_input'

<input id="Department_input" type="text" aria-required="true" size="40" class="field_input ui-widget-content" maxlength="15" aria-invalid="false">

Using driver.find_element_by_xpath("//input[@id='Department_input']") without luck(returning no such element error). There are multiple text boxes on the form that I'd like to enter into also.

Is there another way to approach this?

3
  • 1
    Are you in the correct frame when trying to locate the object? You can open up devtools, hover over the textbox, and discover its id. Great! If Selenium is not pointed to the correct window, nor to the correct frame, you're not going to find the element. Also Check that there are not multiple elements using the same id. Jun 13, 2019 at 17:02
  • Just for Additional knowledge : Go to this link Xpath tutorial This will help you increase basic understanding of your xpath knowledge :)
    – senura
    Jun 14, 2019 at 16:12
  • I have been following my process and realized it might not be looking at the same content. The initial .get grabs a link with a long tag on the end (.aspx?d1=AUTC.......) and the page then opens as .aspx?key=UFKey after an SSO authentication. Is Python still viable here? Jun 17, 2019 at 17:12

3 Answers 3

3

Most probably this occurs because of the execution speed. The code executes before loading the page. Therefore when the code looks for an element with the id='Department_input' it cant find such element and throws exception.

First of all try a Thread.sleep(5000) just before where you look for the element.

Thread.sleep(5000);    
driver.find_element_by_xpath("//input[@id='Department_input']");     

This will pause the execution for 5 seconds and continue. If it works for you try using page factory.
It's better if you use like this since you have ID of the element,

WebElement element = driver.findElement(By.id("Department_input"));     

page-object-pattern-model-page-factory 1

page-object-pattern-model-page-factory 2

Check these 2 tutorials. It will help to understand. Both are for the same task.

2
  • Thanks for the response Joe, however I am running these commands one at a time not executing a .py file so I don't think the sleep part is necessary. Jun 14, 2019 at 20:53
  • Are you sure you are in the right page?
    – Syrus
    Jun 17, 2019 at 3:46
0

try the below:

from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0


WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'Department_input')))
1
  • Please edit your answer to explain how your change will help the OP. That will make the answer much better for everyone.
    – Kate Paulk
    Jun 14, 2019 at 12:22
0

When you land up on the page then first verify if u have landed on required page. Since u are getting no such element, it may be possible that element is not loaded by the time your code has reached to that location. So please try to add some wait before reaching to the element. it should work

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.