A
A
anya_hacker2021-03-22 23:21:32
Python
anya_hacker, 2021-03-22 23:21:32

How to fill a form using Selenium?

I'm trying to enter a number using selenium in the phone input field on the bosch.kofemashini.com website .
I see that selenium selects the field, but for some reason does not enter. In this case, the field is highlighted in red.
Why can't I enter my phone number?

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

phones = ['4951553668', '4950818500', '4954298904']

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

url = 'http://bosch.kofemashini.com/'
driver.get(url)

element = driver.find_element_by_class_name('form-control')
element.send_keys(f"{choice(phones)}")

# btn = driver.find_element_by_css_selector('.btn btn-block btn-danger')
# btn.click()
sleep(15)


6058fc26425ff085244712.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Karbivnichy, 2021-03-22
@anya_hacker

This is:

element = driver.find_element_by_class_name('form-control')
element.send_keys(f"{choice(phones)}")

replace with this:
element = driver.find_element_by_tag_name('input')
element.click()
element.send_keys(choice(phones))

PS: You can also search for an element by the class name, but I'm searching by the tag name.

R
RealLazyCat, 2021-03-22
@RealLazyCat

first wait for the element to be ready for interaction (at least sleep(5000))
then click on it.
then send_keys().

A
Antonio Solo, 2021-03-22
@solotony

read about expectations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question