pythonseleniumselenium-webdriverxpathwebdriverwait

Selenium log in problem in to site problem


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

Solution

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

    gsis