-1

I'm trying to learn how to interact with the internet with python, and followed a tutorial I found on how to make a bot that interacts with tinder. I am able to get a chrome window up, and it can go to the website, but I run into issues when I try to click the login button. Here is the code I used(I imported webdriver from selenium, and sleep from time, but it wouldn't transfer here):

class tinderAI():
def __init__(self):
    self.driver = webdriver.Chrome()
def login(self):
    self.driver.get('https://tinder.com')
    sleep(2)
    fb_btn = self.driver.find_element_by_xpath('//*[@id="modal-manager"]/div/div/div/div/div[3]/div[2]/button')
    fb_btn.click()

The error code I get after using this code is:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="modal-manager"]/div/div/div/div/div[3]/div[2]/button"}

Any help in resolving the issue would be appreciated. Thanks!

Guy
  • 46,488
  • 10
  • 44
  • 88
evanr50
  • 23
  • 2
  • 1
    Make sure this is the right xpath first testing it in the browser. If it is, most likely the element is still not loaded or had disappeared. You may need to wait it to appear with implicit wait in this case. Search for stalled element and implicit waiting in Selenium. – Nikolay Shindarov Feb 28 '20 at 19:17

1 Answers1

0

As per your code trials the locator:

//*[@id="modal-manager"]/div/div/div/div/div[3]/div[2]/button

represents the button with text as Log in with Facebook and to invoke click() on the element you need to induce WebDriverWait for the element_to_be_clickable() reaching till the child <span> and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[type = 'button'][aria-label = 'Log in with Facebook'] span"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@type = 'button' and @aria-label = 'Log in with Facebook']//span"))).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
    
  • Browser Snapshot:

tinder_facebook_login


Reference

You can find a detailed relevant discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352