Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cant get logging element

When i was testing my program, it’s end with code 1

  • here is full error ("Traceback (most recent call last): File "C:\Users\ds072\PycharmProjects\pythonProject\main.py", line 20, in <module> wait.until(EC.element_to_be_clickable((By.XPATH, "/html/body/main/div/div/div/div[1]/div[3]/div[1]/div[1]/input"))).send_keys("my username")")
  • here is my code (https://pastebin.com/RThnY8GY)
    I have tested alternatives for this value ("/html/body/main/div/div/div/div[1]/div[3]/div[1]/div[1]/input") but with out results :C
    element witch i was trying to get

Please help me

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The following is one way to select those fields and login into that website (fields are in an iframe):

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("window-size=1280,720")
webdriver_service = Service("chromedriver/chromedriver") ## path to where you saved chromedriver binary
browser = webdriver.Chrome(service=webdriver_service, options=chrome_options)

wait = WebDriverWait(browser, 10)

url = 'https://portal.librus.pl/rodzina/synergia/loguj'
browser.get(url)

wait.until(EC.element_to_be_clickable((By.XPATH, '//a[@class = "btn btn-third btn-synergia-top btn-navbar dropdown-toggle"]'))).click()
print('clicked to open dropdown') 
wait.until(EC.element_to_be_clickable((By.XPATH, '//a[@href="/rodzina/synergia/loguj"]'))).click()
print('clicked to get the login interface') 
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@id='caLoginIframe']")))
print('switched to iframe')
wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@id="Login"]'))).send_keys('My username')
print('located and wrote into id field')
wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@id="Pass"]'))).send_keys('My password')
print('located and wrote into password field')
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@id="LoginBtn"]'))).click()
print('logging in now...')

This will also print in terminal:

clicked to open dropdown
clicked to get the login interface
switched to iframe
located and wrote into id field
located and wrote into password field

Selenium setup is linux/chrome, you can adapt the code to your own setup, just observe the imports and code after defining the browser.

For Selenium documentation, please see https://www.selenium.dev/documentation/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading