简体   繁体   English

硒不要在现场按下按钮

[英]selenium don't push button on site

i'm trying to make a program that as the first step must login on site edostavka.by having phone and password.我正在尝试制作一个程序,作为第一步必须使用电话和密码登录网站 edostavka.。 If I use "https://edostavka.by/login?screen=withPassword" - program still redirected on "https://edostavka.by/login?screen=phone".如果我使用“https://edostavka.by/login?screen=withPassword” - 程序仍然重定向到“https://edostavka.by/login?screen=phone”。 Luckily there is button "Войти с паролем", which should open "https://edostavka.by/login?screen=withPassword" page.幸运的是有按钮“Войти с паролем”,它应该打开“https://edostavka.by/login?screen=withPassword”页面。 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.无论我如何尝试找到该按钮(通过 XPATH、CLASS_NAME 或 LINK_TEXT)——这些都不起作用。 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"我试过用 WebDriverWait 和 EC 代替 time.sleep,但它对交换“点击”方法没有帮助(我试过“点击()”、“提交()”、“发送键(Keys.ENTER 或 \n) . 另外,我认为问题可能出在 iframe 或脚本中。但是对于 iframe - 页面上有 4 个,而且它们似乎都是空的。对于脚本 - 我仍然没有找到答案:我应该做什么?不得不提到它可以找到甚至用“电话号码”填充行

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也许我的问题很简单而且是新手,但我试图在六七个小时内解决这个问题,但仍然没有找到解决方法

First of read the selenium documentation.首先阅读硒文档。 Then use Chrome Developer tools (you may call by pressing F12 or Ctrl+Shift+I ) to inspect target page elements.然后使用 Chrome 开发者工具(您可以按F12Ctrl+Shift+I调用)检查目标页面元素。

Below I provide an 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这是使用 XPath 的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM