1

I'm recently trying to learn Selenium and found a website that just ignores my attempts to find particular element by ID, name or xpath. The website is here:

https://www.creditview.pl/PL/Creditview.htm

I am trying to select first text window, the one labeled Uzytkownik, the code for it goes like that:

I am trying to find it using several methods:

from selenium import webdriver
browser = webdriver.Chrome()

site = "https://www.creditview.pl/pl/creditview.htm"
browser.get(site)

login_txt = browser.find_element_by_xpath(r"/html//input[@id='ud_username']")
login_txt2 = browser.find_element_by_id("ud_username")
login_txt3 = browser.find_element_by_name("ud_username")

No matter what I try I keep getting: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:

as if the element wasn't there at all.

I have suspected that the little frame containing the field might be an iframe and tried to switch to various elements with no luck. Also tried to check if the element isn't somehow obscured to my code (hidden element). Nothing seems to work, or I am making some newbie mistake and the answer is right in front of me. Finally I was able to select other element on the site and used several TAB keys to move cursor to desired position, but is feels like cheating.

Can someone please point show me how to find the element ? I literally can't sleep because of this issue :)

sudonym
  • 3,788
  • 4
  • 36
  • 61
Mr_Happy
  • 39
  • 10

1 Answers1

1

Given that your element is there, you still need to wait for your element to be loaded/visible/clickable etc. You can do that using selenium's expected conditions (EC).

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

my_XPATH = r"/html//input[@id='ud_username']"
wait_time = 10  # Define maximum time to wait in seconds

driver = webdriver.Chrome()
site = "https://www.creditview.pl/pl/creditview.htm"
driver.get(site)

try:
    my_element = driver.WebDriverWait(driver, wait_time).until(EC.presence_of_element_located(By.XPATH,my_XPATH))
except:
    print ("element not found after %d seconds" % (wait_time))
sudonym
  • 3,788
  • 4
  • 36
  • 61
  • That didn't work unfortunately. The code does not seem to care for delays, instead it just immediatly refuses to acknowledge that there is such an element on the website. Error code is still the same. – Mr_Happy Jun 29 '18 at 20:36
  • did you see "element not found after 10 seconds"? – sudonym Jun 29 '18 at 20:38
  • I'm getting:selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html//input[@id='ud_username']"} – Mr_Happy Jun 29 '18 at 20:42
  • due to the try-except block in my code, that should not happen. Are you working in a jupyter notebook? if so, please restart the kernel. – sudonym Jun 29 '18 at 20:44
  • Yet the element is there. I'm looking at it and browser add-ons that retrieve id, name or xpath have no problems to get the info. I can also browse the code of the page and find the element manually. – Mr_Happy Jun 29 '18 at 20:44
  • Nope, launching it straight from PyCharm. It spits out the error as soon as the page loads. It's as if it was saying: I won't bother to wait for something that isn't even there. Attempts to raise the wait time didn't help. – Mr_Happy Jun 29 '18 at 20:46
  • the page loads before the try/except block, but you dont search for any element at this point. I can't reproduce the issue you are facing - the XPATH is correct, there are 2 elements matching this description present on the website and it works for me. – sudonym Jun 29 '18 at 20:47
  • 1
    Right, I was launching wrong py script. Silly, silly me. Yes, your solution works and I will be happy to apply it. Thank you very much for your time, help and patience. – Mr_Happy Jun 29 '18 at 20:50