1

The homepage for the web application I'm testing has a loading screen when you first load it, then a username/password box appears. It is a dynamically generated UI element and the cursor defaults to being inside the username field.

I looked around and someone suggested using action chains. When I use action chains, I can immediately input text into the username and password fields and then press enter and the next page loads fine. Unfortunately, action chains are not a viable long-term answer for me due to my particular setup.

When I use the webdriver's find_element_by_id I am able to locate it and I am not able to send_keys to the element though because it is somehow not visible. I receive

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible.

I'm also not able to click the field or otherwise interact with it without getting this error.

I have also tried identifying and interacting with the elements via other means, such as "xpaths" and css, to no avail. They are always not visible.

Strangely, it works with dynamic page titles. When the page first loads it is Loading... and when finished it is Login. The driver will return the current title when driver.title is called.

Does anyone have a suggestion?

5
  • Ok confirm me is there loading progress bar appears on login page when you are going to find element??? Commented Aug 23, 2016 at 2:44
  • Yes, it is there. I put a time.sleep(20) before trying to interact with it which is ample time for the login box to appear. Commented Aug 23, 2016 at 15:07
  • actually presence_of_element_located of element just checking element present on the DOM or not while visibility_of_element_located checking present and visible both, means presence_of_element_located also able to find hidden element as well as visible element while visibility gets only visible that's why presence_of_element_located works. Commented Aug 23, 2016 at 22:48
  • Now problem during send_keys, because selenium can not be intract to element until it's not visible that's why you are in trouble may be there are some hidden CSS works on desire element which makes it invisible that's why selenium unable to interact with it but don't worry you are still able to set value using execute_script. Commented Aug 23, 2016 at 22:48
  • Now you can try to set value on input element instead of using send_keys after element. Try with second updated answer and let me know. Commented Aug 23, 2016 at 22:49

2 Answers 2

1

Actually if there is loading progress bar appears in you login page, You should try using WebDriverWait to wait until element is getting visible as below :-

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC wait = WebDriverWait(driver, 10) element = wait.until(EC.visibility_of_element_located((By.ID, "enter element id here"))) # now use send_keys element.send_keys("enter value here") 

Edited1 :- If you're getting TimeoutException, I would suggest you try to wait before finding element to to be invisible loading progress bar using WebDriverWait instead of hard coded sleep wait then find desire element as below :-

wait = WebDriverWait(driver, 10) wait.until(EC.invisibility_of_element_located((By.ID, "enter loading progress bar id or other locators here"))) #now after invisible of loading progress bar wait for desire element element = wait.until(EC.presence_of_element_located((By.ID, "enter element id here"))) # now use send_keys element.send_keys("enter value here") 

Edited2 :- actually presence_of_element_located of element just checking element present on the DOM or not while visibility_of_element_located checking present and visible both, means presence_of_element_located also able to find hidden element as well as visible element while visibility gets only visible that's why presence_of_element_located works.

Now problem during send_keys, because selenium can not be intract to element until it's not visible that's why you are in trouble may be there are some hidden CSS works on desire element which makes it invisible that's why selenium unable to interact with it but don't worry you are still able to set value using execute_script.

Now you can try to set value on input element instead of using send_keys after element finding as :-

driver.execute_script("arguments[0].value = arguments[1]", element, "enter your value here") 
Sign up to request clarification or add additional context in comments.

11 Comments

I use a hard-coded wait to ensure the element is on screen, then did what you suggested. The element is clearly visible on the screen and in the source but I still get a TimeoutException raised by the wait.until() I tried switching frames, thinking it could be something wonky like that, but did not help. Is there some sort of refresh I need to do for selenium to register the new source or something?
Ok then instead of hard coded wait use WebDriverWait to wait until loading bar invisible then find element, try edited answer and let me know...:)
I tried doing that. It can find the loading bar just fine, and notices when it goes invisible, but still incapable of locating the username and password fields. I'm considering just using action chains for this part and trying to automate other parts of the site to see if this will be a problem I encounter everywhere.
What error this time?? And could you tell me which locator are you using to locate input element?? And make sure your locator is correct and locate to correct element as well..:)
I use wait.until(EC.invisibility_of_element_located((By.XPATH, "//h2[contains(.,'Loading application')]"))) to find the loading bar, which works. I use wait.until(EC.visibility_of_element_located((By.ID, 'uname'))) to find the username field, which doesn't. The error is TimeoutException, so it is looking for it for 10 seconds, fails, the throws the error.
|
0

As suggested by saurabh , use 1 self.wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, OR.Sub_categories)))

Else put a sleep and see however it is not advisable to use that, may be the xpath you have changes at the time of page load

1 Comment

I tried both, including using an explicit wait until I know for sure the element was on the screen and then trying to locate it with a EC.visibility function. It still can't locate the box.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.