1

I'm trying to make a bot that automatically opens my server for me. The problem is there's a human verification check in that website. When the number of people in the queue is less than 300 a button appears. I want my bot to click that button when it appears but I dunno how to do it.

Xpath of that button is //*[@id="confirm"]

3 Answers3

0

Let's say it takes 100 seconds for the queue to build up, you can wait till then with :

time.sleep(100)

You can also do it via Selenium with :

browser = webdriver.Chrome()
browser.implicitly_wait(100)
biruk1230
  • 3,042
  • 4
  • 16
  • 29
0
    # if not visible will raise a exception
    try:
        element = WebDriverWait(driver, 20).until(
        EC.visibility_of_element_located((By.ID, "elementID"))

        # click
        driver.find_element_by_id("elementID").click()
    except Exception:
        # do action if not visible

source: https://selenium-python.readthedocs.io/waits.html

Ramon Medeiros
  • 2,272
  • 2
  • 24
  • 41
0

If you want to click on element then we have to wait till element able to receive click. This way you are able to click whenever queue less than 300 in give timeout period 40 seconds (selenium by default use polling interval for wait condition every 500 milli second)

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

element = WebDriverWait(driver, 40).until(
EC.element_to_be_clickable((By.XPATH, "//*[@id="confirm"]")))
element.click()
Muzzamil
  • 2,823
  • 2
  • 11
  • 23