0

I try to autofollow people that are commenting under various pictures and im on the step where i need to hover over profile names to let a window popup

(u can try it yourself to see what i mean(https://www.instagram.com/p/CLMCNSenf-E/ hover ur mouse over a name)),

but when i use the "move_to_element" command it shows me the error message raise AttributeError("move_to requires a WebElement"). I dont really understand the meaning of it, can someone help me out? I posted the code below. Dont forget to replace the fillers with ur own login information if u want to try it out.

from selenium import webdriver
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains

browser = webdriver.Chrome()
action = ActionChains(browser)

url = "https://www.instagram.com/"
browser.get(url)

sleep(1)
browser.find_element_by_xpath("/html/body/div[2]/div/div/div/div[2]/button[1]").click()#popup

#Login
browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input")\
    .send_keys("username")
browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input")\
    .send_keys("password")
browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[3]/button").click()
sleep(3)

browser.find_element_by_xpath("/html/body/div[1]/section/main/div/div/div/div/button").click()#popup
browser.find_element_by_xpath("/html/body/div[4]/div/div/div/div[3]/button[2]").click()#popup
url = "https://www.instagram.com/scarlxrd/"
browser.get(url)
browser.find_element_by_xpath("/html/body/div[1]/section/main/div/div[3]/article/div/div/div[1]/div[1]/a/div/div[2]").click()#Bildwahl
sleep(2)
follow = "/html/body/div[6]/div/div/div[4]/button"

a = 1
for i in range(5):
    for i in range(1, 11):
            link = "/html/body/div[5]/div[2]/div/article/div[3]/div[1]/ul/ul[{a}]/div/li/div/div[1]/div[2]/h3/div/span/a".format(a=i)
            action.move_to_element(link).move_to_element(follow).click().perform()                      
            sleep(1)
Samet
  • 33
  • 1
  • 6
  • Does this answer your question? [Python. Selenium. drag\_and\_drop error 'AttributeError: move\_to requires a WebElement'](https://stackoverflow.com/questions/59600235/python-selenium-drag-and-drop-error-attributeerror-move-to-requires-a-webele) – Umair Mubeen Mar 26 '21 at 11:13
  • unfortunately not, i tried now to split the link and follow commands to "action.move_to_element(link).perform()" and "browser.find_element_by_xpath(follow).click()" but that also didnt worked. – Samet Mar 26 '21 at 11:21
  • use precise and absolute xpath – Umair Mubeen Mar 26 '21 at 11:23
  • cant find precise, is it possible that u mean relative and absolute xpath? – Samet Mar 26 '21 at 11:38

1 Answers1

0
 link=browser.find_element_by_xpath("yourxpath")

You need to find a webelement before using move to.

Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32