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?

asked Jun 13, 2019 at 15:58
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. Commented 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 :) Commented 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? Commented 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.

answered Jun 14, 2019 at 4:34
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. Commented Jun 14, 2019 at 20:53
  • Are you sure you are in the right page? Commented 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')))
Kate Paulk
31.5k8 gold badges56 silver badges109 bronze badges
answered Jun 14, 2019 at 12:06
1
  • Please edit your answer to explain how your change will help the OP. That will make the answer much better for everyone. Commented 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

answered Jun 14, 2019 at 12:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.