Home > database >  Selenium element is not clickable even after excplicitly waiting for it to be
Selenium element is not clickable even after excplicitly waiting for it to be

Time:04-26

I'm trying to open a form, wait for all of it's elements to be loaded and fill one of the form's fields. Form is loading, and I'm setting a WebdriverWait to explicitly wait for my element to be clickable. But on elem.click() I get exception

Element...is not clickable at the point

Code sample I'm using:

def fill_element(driver, xpath, keys, secs=2000):
   print(f"\nFilling for {xpath}...")
   elem = WebDriverWait(driver, secs).until(EC.element_to_be_clickable((By.XPATH, xpath)))
   elem.clear()
   elem.click()
   elem.send_keys("")
   elem.send_keys(keys)

If I don't use "click" and just trying to send keys - nothing happens. No exceptions and no form filling.

Could someone please advise how to use Wait properly?

P.S. Window was maximized even before clicking on the form to open, so it shoudln't be the problem.

UPD Full code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from pathlib import Path
import time

def fill_element(driver, xpath, keys, secs=2000):
   print(f"\nFilling for {xpath}...")
   element = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, xpath)))
   driver.find_element_by_xpath(xpath).send_keys("test")


def authorize(driver):
   email = "xxx"
   pwd = "xxx"
   my_acc_button = driver.find_element(By.XPATH, "//li[@class='menuOverride showLoginPopUp menu-account-icon']")
   my_acc_button.click()

   email_xpath = "// INPUT[@ type='email']"
   fill_element(driver, email_xpath, email)
   pwd_xpath = "// INPUT[@ type='password']"
   fill_element(driver, pwd_xpath, pwd)

   login_button = driver.find_element(By.XPATH, "//div[@class='btn green-color']")
   # login_button.click()


driver_path = r'D:\Projects\cheater_buster_parser\utils\chromedriver.exe'
driver = webdriver.Chrome(driver_path)
driver.maximize_window()

start_url = 'https://www.cheaterbuster.net/'
driver.get(start_url)
authorize(driver)

CodePudding user response:

According to new updates, use the following:


from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from pathlib import Path
import time

def fill_element(driver, xpath, keys, secs=2000):
   print(f"\nFilling for {xpath}...")
   element = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, xpath)))
   driver.find_element_by_xpath(xpath).send_keys("test")


def authorize(driver):
   email = "xxx"
   pwd = "xxx"
   my_acc_button = driver.find_element(By.XPATH, "//li[@class='menuOverride showLoginPopUp menu-account-icon']")
   my_acc_button.click()

   email_xpath = "(//INPUT[@type='email'])[2]"
   fill_element(driver, email_xpath, email)
   pwd_xpath = "(//INPUT[@type='password'])[3]"
   fill_element(driver, pwd_xpath, pwd)

   login_button = driver.find_element(By.XPATH, "//div[@class='btn green-color']")
   # login_button.click()


driver_path = r'D:\Projects\cheater_buster_parser\utils\chromedriver.exe'
driver = webdriver.Chrome(driver_path)
driver.maximize_window()

start_url = 'https://www.cheaterbuster.net/'
driver.get(start_url)
authorize(driver)

CodePudding user response:

Use the foloowing code but make sure if this element is button to click or text field then send keys to it. (According to your info i think its text field

def fill_element(driver, xpath, keys, secs=2000):
   print(f"\nFilling for {xpath}...")
   element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "xpath")))
   elem=driver.find_element_by_xpath(xpath)
   elem.clear()
   elem.click()
   elem.send_keys("")
  • Related