0

Hello stackoverflow comunity, i'm facing a problem with .find element of selenium. I'm programing in python and using google chrome.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time


chrome_driver_path = "C:\Development\chromedriver.exe"
driver = webdriver.Chrome(service=Service(chrome_driver_path))

driver.get("https://tinder.com/")
time.sleep(5)


accept = driver.find_element(By.XPATH, value='//*[@id="c-1351236777"]/div/div[1]/div/div/main/div/div[2]/div/div[3]/div/div/button[2]')

accept.click()
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'value' must be a string
  (Session info: chrome=110.0.5481.104)
Stacktrace:
Backtrace:
    (No symbol) [0x002B6643]
    (No symbol) [0x0024BE21]
    (No symbol) [0x0014DA9D]
    (No symbol) [0x001813F3]
    (No symbol) [0x0018147B]
    (No symbol) [0x001B8DFC]
    (No symbol) [0x0019FDC4]
    (No symbol) [0x001B6B09]
    (No symbol) [0x0019FB76]
    (No symbol) [0x001749C1]
    (No symbol) [0x00175E5D]
    GetHandleVerifier [0x0052A142+2497106]
    GetHandleVerifier [0x005585D3+2686691]
    GetHandleVerifier [0x0055BB9C+2700460]
    GetHandleVerifier [0x00363B10+635936]
    (No symbol) [0x00254A1F]
    (No symbol) [0x0025A418]
    (No symbol) [0x0025A505]
    (No symbol) [0x0026508B]
    BaseThreadInitThunk [0x762600F9+25]
    RtlGetAppContainerNamedObjectPath [0x77167BBE+286]
    RtlGetAppContainerNamedObjectPath [0x77167B8E+238]
    (No symbol) [0x00000000]

this is the code and it doesn't run. And i think it's because the body tag of the html code is closed, I need to open it with selenium. I actually can open it if i do right click in when i inspect the code manually. Then I click in "expand recursively", then the code runs well, but i don't know how to do it automatically with python.

Student
  • 11
  • 1

1 Answers1

0

The I accept element is a dynamic element, so to click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategy:

  • Using XPATH:

    driver.get('https://tinder.com/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button//div[text()='I accept']"))).click()
    
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352