Automation Webdriver with python

Asked

Viewed 188 times

0

I’m using the python Selenium Webdriver to log in to a site to do some tasks, I’m able to click login, but it doesn’t take the input I ask to type.

This is code Selenium:

import time
import requests
import pandas as pd
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup

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

url = "https://gool.cittati.com.br/Login.aspx?ReturnUrl=%2f"

driver.get(url)
driver.implicitly_wait(20)

login = driver.find_element_by_xpath("//div[@class='listaIcones']//ul//li//input[@id='ucTrocarModulo_btnIconeUrbano']")
login.click()

usarname = driver.find_element_by_xpath("//div[@class='form']//div[@id='ucLogarUsuario_divCampos']//div[@id='ucLogarUsuario_pnlLogin']//div[@class='user']//input[@id='ucLogarUsuario_txtLogin']").send_keys("username")
#password = driver.find_element_by_xpath("//div[@class='form']//div[@id='ucLogarUsuario_divCampos']//div[@id='ucLogarUsuario_pnlSenha']").send_keys("password")

driver.quit()

And this is the html code I’m trying to access:

 <div class="form">
<div id="ucLogarUsuario_divCampos" class="campos" onkeydown="return logar(event);">
        <div id="ucLogarUsuario_pnlLogin">
                
            <label>
                Login</label>
            <div class="user">
                <input name="ucLogarUsuario$txtLogin" type="text" maxlength="100" id="ucLogarUsuario_txtLogin" tabindex="1" />
            </div>
        
            </div>
        <div id="ucLogarUsuario_pnlSenha">
                
            <label>
                Senha</label>
            <div class="user">
                <input name="ucLogarUsuario$txtSenha" type="password" maxlength="15" id="ucLogarUsuario_txtSenha" tabindex="2" class="userFocus" value="" />
            </div>
        
            </div>

When I run the code Selenium shows the following message: Elementnotinteractableexception: Message: element not interactable

Does anyone know what’s going on ?

  • may be that the element is not yet available, try to get a Wait for a few seconds

  • Did you notice if while trying to fill these fields, they are visible on the screen so that you yourself without automation could type in them, or if they were behind a div or something similar?

1 answer

0


The element is not yet available for interaction, to solve this you can use an explicit waiting technique as below.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC



driver.get("https://gool.cittati.com.br/Login.aspx?ReturnUrl=%2f")
driver.find_element_by_id('ucTrocarModulo_btnIconeUrbano').click()

txt_username_locator = (By.XPATH, "//div[@class='form']//div[@id='ucLogarUsuario_divCampos']//div[@id='ucLogarUsuario_pnlLogin']//div[@class='user']//input[@id='ucLogarUsuario_txtLogin']")
# Recomendo mudar o locator acima para (By.ID, "ucLogarUsuario_txtLogin"), fica mais legível e preciso
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable(txt_username_locator))
element.send_keys("username")

  • 1

    Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.