Home > Net >  selenium don't push button on site
selenium don't push button on site

Time:12-17

i'm trying to make a program that as the first step must login on site edostavka.by having phone and password. If I use "https://edostavka.by/login?screen=withPassword" - program still redirected on "https://edostavka.by/login?screen=phone". Luckily there is button "Войти с паролем", which should open "https://edostavka.by/login?screen=withPassword" page. But selenium can't find it.

My code here:

from selenium import webdriver
import time

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from fake_useragent import UserAgent as ua
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

ua = ua(browsers='chrome')

driver_service = Service(executable_path=r'C:\Users\37533\Desktop\dostavka\dostavka\chromedriver\chromedriver.exe')
options = webdriver.ChromeOptions()
options.add_argument(f'user-agent={ua}')
driver = webdriver.Chrome(service=driver_service)
driver.maximize_window()

#url = 'https://edostavka.by/login?screen=withPassword'
url = 'https://edostavka.by/login?screen=phone'
try:
    driver.get(url=url)
    time.sleep(3)
    driver.find_element(By.NAME, 'phone').send_keys('132456789')
    driver.find_element(By.LINK_TEXT, 'Войти с паролем').send_keys(Keys.ENTER)
    time.sleep(5)
except Exception as e:
    print(e)
finally:
    driver.close()
    driver.quit()

It was no matter how i tried to find that button(through XPATH, CLASS_NAME, or LINK_TEXT) - none of this worked. I tried put WebDriverWait and EC instead of time.sleep, but it didn't help aswell as swapping "click" methods(I tried 'click()', 'submit()', 'send_keys(Keys.ENTER or \n). Also, I figure that problem might be in iframe or scripts. But for iframe - there are 4 on the page and all of them seems to be empty. For scripts - I still didn't find answer: what and should I do? Had to mention that it can find and even fill line with "phone number"

Every time i run the code i get that message

Message: no such element: Unable to locate element: {"method":"link text","selector":"Войти с паролем"}
  (Session info: chrome=108.0.5359.125)
Stacktrace:
Backtrace:
    (No symbol) [0x00FEF243]
    (No symbol) [0x00F77FD1]
    (No symbol) [0x00E6D04D]
    (No symbol) [0x00E9C0B0]
    (No symbol) [0x00E9C22B]
    (No symbol) [0x00ECE612]
    (No symbol) [0x00EB85D4]
    (No symbol) [0x00ECC9EB]
    (No symbol) [0x00EB8386]
    (No symbol) [0x00E9163C]
    (No symbol) [0x00E9269D]
    GetHandleVerifier [0x01289A22 2655074]
    GetHandleVerifier [0x0127CA24 2601828]
    GetHandleVerifier [0x01098C0A 619850]
    GetHandleVerifier [0x01097830 614768]
    (No symbol) [0x00F805FC]
    (No symbol) [0x00F85968]
    (No symbol) [0x00F85A55]
    (No symbol) [0x00F9051B]
    BaseThreadInitThunk [0x771800F9 25]
    RtlGetAppContainerNamedObjectPath [0x779C7BBE 286]
    RtlGetAppContainerNamedObjectPath [0x779C7B8E 238]

Maybe my question easy and newbie, but i tried to fix this problem over six-seven hours and still didn't find the way of solving

CodePudding user response:

First of read the selenim documentation. Then use Chrome Developer tools (you may call by pressing F12 or Ctrl Shift I) to inspect target page elements.

Below I provie some example solution for your case:

    # accept coockies
    driver.find_element(By.XPATH, "//button[@class='button button_size_medium button_type_subtle accept-cookies_accept__mok-Y']").click()
    time.sleep(2)
    # change login mode to with password
    driver.find_element(By.XPATH, "//button[@class='button button_size_large button_type_subtle phone_button__2Z9fs phone_button__padding__e0VFd']").click()
    time.sleep(2)
    # type phone number
    driver.find_element(By.XPATH, "//input[@class='index-module_wrapperPhone__input__KD5gF']").send_keys('132456789')
    time.sleep(2)
    # type password
    driver.find_element(By.XPATH, "//input[@class='input__input input__input_size_medium']").send_keys('Password')
    time.sleep(2)
    # click to eye icon
    driver.find_element(By.XPATH, "//button[@class='withPassword_login__form_password_button__3Zrhk']").click()
    time.sleep(2)

This is how to use XPath

  • Related