A
A
anya_hacker2021-03-23 13:03:30
Python
anya_hacker, 2021-03-23 13:03:30

What is the method for clicking the button?

I rummaged through all possible methods of searching for an element using selenium, but for some reason none of them solves the task. Could you explain why none of the following methods (starting with a string,
element = driver.find_element_by_class_name(....
no method can click on the field with a phone number to insert text?
How should I choose the right method correctly?
Code:

from seleniumwire import webdriver
from time import sleep
from random import choice

phones = ['9641553668', '9640818500', '9644298904']

driver = webdriver.Chrome(
    executable_path='chromedriver.exe'
)

url = 'https://msk.dyso-srvce.ru/?utm_source=yandex&utm_medium=poisk&utm_campaign=1.1_obshie_remont&utm_content=4325113785&utm_term=%D1%80%D0%B5%D0%BC%D0%BE%D0%BD%D1%82%20%D0%B4%D0%B0%D0%B9%D1%81%D0%BE%D0%BD&yclid=1266237122419121296'

driver.get(url)
driver.maximize_window()
sleep(7)

# =========Закрытие всплывающего окна==================
btn = driver.find_element_by_xpath("//button[@class='modalinf-link']")
btn.click()
# =========Закрытие всплывающего окна==================

element = driver.find_element_by_name('qfuserphone[]')
# element = driver.find_element_by_class_name(" phone-sl")
# element = driver.find_element_by_xpath("//input[@class=' phone-sl']")
# element = driver.find_element_by_css_selector("#input[name='qfuserphone[]']")

element.click()
element.send_keys(choice(phones))

sleep(3)

btn = driver.find_element_by_class_name("btn btn-primary sbmt-sliderr")
# btn = driver.find_element_by_name('qfsubmit')
# btn = driver.find_element_by_xpath("//input[@class='btn btn-primary sbmt-sliderr']")
# btn = driver.find_element_by_css_selector("#input[name='qfsubmit']")

btn.click()
btn.send_keys(choice(phones))

sleep(3)


Website:
https://msk.dyso-srvce.ru/?utm_source=yandex&utm_m...
Website html screen:
6059bbc5cf438930679907.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-03-23
@anya_hacker

The class is what the class is for, so that there are several elements on the page. There are already 14 elements with the class "phone-sl".
With qfuserphone[] it's the same, there are multiple elements, and you choose the wrong one.
In this case, you need a second element on the page, so you can simply find several objects: Take the second and work with it. In the end it will look like:
driver.find_elements_by_name('qfuserphone[]')

element = driver.find_elements_by_name('qfuserphone[]')[1]

element.click()
element.send_keys(choice(phones))

ps: no need to click

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question