0

I am trying to get selenium to wait for the page to load using a specific id that is nested with in other HTML; which I don't have much experience with. The id I am using is icon, which is the zoom functionality. How would I select this id vs. top level id? The task I am attempting to preform is doing so before the page is loaded and I need the page fully loaded before any other actions proceed.

This is the code I have so far but currently it times out and continually reloads trying to find the id.

 delay = 60
 for i, c in enumerate(coordinates):
     try:
         filepath = file + str(i) + '.png'
         lat, lon = c.split(';')
         url = "https://earth.google.com/web/@{},{},1573.2221546a,277.89739987d,35y,0.69169508h,0.45101597t,-0r".format(lat, lon)
         driver.get(url)
         WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'icon')))
         driver.save_screenshot(filepath)
         break
     except TimeoutException:
         print ("Loading took too much time!")
Amit
  • 19,780
  • 6
  • 46
  • 54
eeskonivich
  • 121
  • 4
  • 15
  • Sorry a couple of errors. The By.TAG_NAME should be By.ID and the 'earth-app' should be 'icon'. – eeskonivich May 31 '17 at 03:40
  • you can edit the question to correct it. What is the value of `delay`? May be you need to adjust that. – Amit May 31 '17 at 03:42
  • @Amit, I corrected that and currently my delay is set to 60 and I have tried lesser times as well. – eeskonivich May 31 '17 at 03:48
  • have you tried it without running it in for loop i.e. does it work for a single value. Also what is the error you are getting? – Amit May 31 '17 at 03:51
  • I have not tried it outside the loop. I just added another part that I forgot that is important. So I am getting a TimeoutException error and print saying loading took too much time. – eeskonivich May 31 '17 at 04:00
  • @eeskonivich, required element located in several nested `shadow-root` blocks. [This answer](https://stackoverflow.com/questions/42468715/selenium-webdriver-cant-find-elements-at-chrome-downloads/42481469#42481469) might help you – Andersson May 31 '17 at 11:27
  • @Andersson could you explain what is going on there? specifically with the arguments passed in and the shadow variable. – eeskonivich May 31 '17 at 13:48
  • @eeskonivich, you should find each element with embedded `#shadow-root` consequently with CSS selector like `"body/deep/tag_name"`. Eventually to get access to elements in shadow root you should execute `JavaScript` `'return arguments[0].shadowRoot;'` which returns an actual `DOM` – Andersson Jun 01 '17 at 04:49
  • Thank you for the explanation. I was able to solve my problem with a generic `time.sleep()`. – eeskonivich Jun 01 '17 at 14:42

0 Answers0