1

I need your help to log in to this site with selenium python. I cannot understand if html is by xpath or by id or something else. I try so much but did not work. So i ask you.

I need to fix insert username, password and log in button

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import os
from time import sleep

USER = os.getenv('myuser')
PASS = os.getenv('mtypass')

driver = webdriver.Chrome()
#driver.get('https://exoikonomo2020.gov.gr/')

driver.get('https://exoikonomo2020.gov.gr/web/exoikonomese-kat-oikon/login')


#LoginURL = "//*[@id="p_p_id_56_INSTANCE_zSwUFIXoJ25s_"]/div/div/div[1]/div/div/div[2]/div/p[1]/a/img"
ContinueButton = "//span[text()='Συνέχεια']"

#ContinueButton = "//*[@id="_exoik_login_WAR_exoikonomov2portlet_:scribeOAuthBeanForm:j_idt116"]/span[2]"
UsernameURL = "text"
PasswordURL = "password"
LoginButtonURL = "loginForm"
Continue2 = "Εξουσιοδότηση"


#ButtonURL = "//button[@id='id_next']"
#WebURL = "//a[@id='id_web_app_link']"
#MonthsFromToday = "//input[@value='Run until 3 months from today']"

#LoginElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(LoginURL))
#LoginElement.click()

Continue1Element = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(ContinueButton))
Continue1Element.click()



UserElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(UsernameURL))
UserElement.clear()
UserElement.send_keys(USER)

PasswordElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(PasswordURL))
PasswordElement.clear()
PasswordElement.send_keys(PASS)

LogInButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(LoginButtonURL))
ButtonElement.click()

Continue2Element = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(Continue2))
Continue2Element.click()


#WebElement =  WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(WebURL))
WebElement.click()

#MonthsElement =  WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(MonthsFromToday))
MonthsElement.click()

sleep(5)

driver.quit()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

1

This should do the trick:

username = driver.find_element_by_css_selector("input[name='j_username']")
password = driver.find_element_by_css_selector("input[name='j_password']")
button = driver.find_element_by_css_selector("input[type='button']")
username.send_keys(USER)
password.send_keys(PASS)
button.click()
goalie1998
  • 1,427
  • 1
  • 9
  • 16
0

To send a character sequence to the username password field and click on the login button within the website you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using XPATH:

    driver.get("https://exoikonomo2020.gov.gr/web/exoikonomese-kat-oikon/login")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Συνέχεια']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='j_username']"))).send_keys("ΔημήτρηςΤσινίκος@stackoverflow.com")
    driver.find_element(By.XPATH, "//input[@name='j_password']").send_keys("ΔημήτρηςΤσινίκος")
    driver.find_element(By.XPATH, "//input[@value='Είσοδος']").click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

gsis

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

I present the image of my try! It works for me, image

I also need to learn how to upload file with python.... (Here there is button for example to upload picture from computer). That is easy i think. I just to search in google and youtube....

Also i need to learn how to ask to put , username , password and other fills. So i make forms for another users....and export otheruser.py

My best is to make it graphical! What program is to make it graphical?

Thank you very much!