I am trying to complete the proyect "Tinder swiping boot" from the Udemy course "100 Days of Code: The Complete Python Pro Bootcamp". However, I am not able to perform more that one swiping after loging in on the Tinder website. Is it possible the XPath of an element to change with every new picture displayed? I tried using CSS selector and class to see if the like button can be selected but not luck yet.
Here is my code:
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
#Entering the website
website_url = "https://tinder.com/"
driver = webdriver.Chrome()
driver.get(website_url)
# use delay function to get all tags
driver.implicitly_wait(20)
# Clicking on sign in button
tinder_login_button = driver.find_element(By.XPATH, '//*[@id="q1434999767"]/div/div[1]/div/main/div[1]/div/div/div/div/header/div/div[2]/div[2]/a/div[2]/div[2]') #'//*[@id="c1606223767"]/div/div[1]/div/main/div[1]/div/div/div/div/header/div/div[2]/div[2]/a/div[2]/div[2]')
tinder_login_button.click()
sleep(4)
.
.
#login into tinder website using facebook
.
.
#click I accept cookies button
iaccept_button = driver.find_element(By.XPATH, '//*[@id="q1434999767"]/div/div[2]/div/div/div[1]/div[1]/button') #'//*[@id="c1606223767"]/div/div[2]/div/div/div[1]/div[1]/button/div[2]/div[2]')
iaccept_button.click()
sleep(5)
#like button
for n in range(100):
sleep(5)
try:
like_button = driver.find_element(By.XPATH, '//*[@id="q1434999767"]/div/div[1]/div/main/div[1]/div/div/div[1]/div[1]/div/div[4]/div/div[4]/button')
like_button.click()
except NoSuchElementException:
sleep(5)
I tried using CSS selector and ID to see if the like button can be selected and I saw that these element change every time I open the website, Is it possible the XPath of an element to change with every new picture displayed?