Selenium python - element is not clickable at point Selenium python - element is not clickable at point selenium selenium

Selenium python - element is not clickable at point


The URL you posted doesn't contain a //*[@id="react-root"]/section/nav/div/div/div/div[1]/div[2]/div[2]/div/a[1]. But I assume that when moving the (virtual) mouse cursor from your search_field to the element you want to click, it causes some MouseOver effect on the page, in the sense that an overlay pops up or something, hiding the clickable element behind itself.

I had the same problem and solved it like this:How to avoid MouseOver on Selenium Click()


This gets what you want:

from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECdef wait(dr, x):    element = WebDriverWait(dr, 5).until(        EC.presence_of_element_located((By.XPATH, x))    )    return elementdriver = webdriver.Chrome()driver.set_window_size(1024, 768)driver.get('https://www.instagram.com/accounts/login/')driver.implicitly_wait(10)username_field = driver.find_element_by_name('username')password_field = driver.find_element_by_name('password')username_field.send_keys("user")password_field.send_keys("pass")password_field.send_keys(Keys.RETURN)    def find_tag():    search_field = driver.find_element_by_xpath('//nav/div/div/div/div/input')    search_field.send_keys('moscow')    wait(driver, '//*[@id="react-root"]/section/nav/div/div/div/div[1]/div[2]/div[2]/div/a[1]').click()def follow_from_tag():    top_20_posts = [a.get_attribute("href") for a in                    driver.find_elements_by_xpath("//a[contains(@href,'?tagged=moscow')]")[:20]]    for href in top_20_posts:        driver.get(href)        print(href)        btn = wait(driver, "//button[text()='Follow']")       # btn.click() # uncomment to follow

The output of the prints:

https://www.instagram.com/p/BD249tsxEbl/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79810>https://www.instagram.com/p/BD2puxzELOu/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79790>https://www.instagram.com/p/BD2jrmyP8ec/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79750>https://www.instagram.com/p/BD2v9NyvzIs/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79810>https://www.instagram.com/p/BD2qkcZm8cg/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79790>https://www.instagram.com/p/BD2sEWzLlEF/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79750>https://www.instagram.com/p/BD25VA2vI6t/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79810>https://www.instagram.com/p/BD2fRXoB1t2/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79790>https://www.instagram.com/p/BD2jYlfE0Yw/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79750>https://www.instagram.com/p/BD2s0PtoRP1/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79810>https://www.instagram.com/p/BD2mn_QBQPK/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79790>https://www.instagram.com/p/BD2zTmqM-5h/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79750>https://www.instagram.com/p/BD2q6Qfqc5q/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79810>https://www.instagram.com/p/BD2iivvDbiO/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79790>https://www.instagram.com/p/BD2-WU2msdO/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79750>https://www.instagram.com/p/BD2Qa2Rn0GV/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79810>https://www.instagram.com/p/BD2ffCZDR8L/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79790>https://www.instagram.com/p/BD2kqDhwywb/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79750>https://www.instagram.com/p/BD2r4M7lf-h/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79810>https://www.instagram.com/p/BD2t3PTAlJC/?tagged=moscow<selenium.webdriver.remote.webelement.WebElement object at 0x7fa717d79790>

You might want to add error handling and use better xpaths but it gets what you need, just uncomment the btn.click() if you want to follow.

I missed you want to check the text, if you want to check the text, we can use contains with "Follow" as the word to match:

def follow_from_tag():    top_20_posts = [a.get_attribute("href") for a in                    driver.find_elements_by_xpath("//a[contains(@href,'?tagged=moscow')]")[:20]]    for href in top_20_posts:        driver.get(href)        print(href)        btn = wait(driver, "//button[contains(text(),'Follow')]")        print(btn.text)

The output now after I randomly chose one to follow:

https://www.instagram.com/p/BD23RGrkLEN/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2jrmyP8ec/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD249tsxEbl/?tagged=moscowFOLLOWINGhttps://www.instagram.com/p/BD2v9NyvzIs/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2qkcZm8cg/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2sEWzLlEF/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD25VA2vI6t/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2fRXoB1t2/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2s0PtoRP1/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2jYlfE0Yw/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2mn_QBQPK/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2zTmqM-5h/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2-WU2msdO/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2q6Qfqc5q/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2iivvDbiO/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD29pcrDs6o/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2Qa2Rn0GV/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2ffCZDR8L/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2kqDhwywb/?tagged=moscowFOLLOWhttps://www.instagram.com/p/BD2r4M7lf-h/?tagged=moscowFOLLOW

So you just need an if btn.text.lower() == "follow" etc..