How to use WebDriverWait with undetected_chromedriver to send text within www.365sport365.com if iframe is present?

Question:

I wanted to make a script that searches for given matches, but it seems I’m unable to interact with the site and I’m not sure if it’s beacause there’s an iframe that I’m ignoring or the site has some form of protection against automated scripts. I tried using .click just to see if I script can interact with the site at all, but that failed as well.

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

driver = uc.Chrome(use_subprocess=True)
driver.get('https://www.365sport365.com/#/AX/')
driver.maximize_window()
match = "testbarcelona"
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/div/div[4]/div[1]/div/div[2]/div[2]/input"))).send_keys(match)
time.sleep(120)

When I run the script, site opens and that all that happens. Haven’t been able to make script be able to click or fill search bar.

Tried to make a script that searches for matches, but was unable to interact with the site at all.

Asked By: JakeM

||

Answers:

The search field within the website isn’t within any iframe as such.


To send a character sequence to the search field you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Code Block:

    import undetected_chromedriver as uc
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    driver = uc.Chrome(executable_path='C:\BrowserDrivers\chromedriver.exe', use_subprocess=True)
    driver.maximize_window()
    driver.get('https://www.365sport365.com/#/AX/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.sml-SearchTextInput"))).send_keys("testbarcelona")
    driver.save_screenshot("search.png")
    
  • Browser Snapshot:

search.png

  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
Answered By: undetected Selenium