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 :)

1 Answer 1

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))
Sign up to request clarification or add additional context in comments.

8 Comments

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.
did you see "element not found after 10 seconds"?
I'm getting:selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html//input[@id='ud_username']"}
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.
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.
|

Your Answer

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.