Home > OS >  Click follow button if possible and close tab after checking/following Instagramm with Selenium
Click follow button if possible and close tab after checking/following Instagramm with Selenium

Time:03-09

I tried with xpath, find by name etc. but it always doesnt find the follow button i already made it sign in accept cookie and all that i can give the code i got in discord i dont wanna do it here because of a certain reason, Thanks for any help

driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/header/section/div[1]/div[2]/div/div/div/span/span[1]/button').click()

ik its deprecated btw. Brave TheRealChicken#4398 I tried it at other threads on this forum but they dont seem to work

CodePudding user response:

You are using absolute xpath which is not preferred because a minor change in website renders your code ineffective. Always try to use relative xpath.

Anyway, try this code, it will work.

driver.find_element_by_xpath("//main[@role='main']//button/div[contains(string(), 'Follow')]").click()

Change the text "Follow" as per what you see in your language on instagram. For german language, the code should be

driver.find_element_by_xpath("//main[@role='main']//button/div[contains(string(), 'Folgen')]").click()
  • Related