0

I am trying to click on the anchor tag on instagram's page which says log in. Here is my code.

browser = webdriver.Chrome()
browser.get('https://instagram.com')
login_elem = browser.findElement(By.xpath('//p/a[text() = "Log in"'))
login_elem.click()

The browser opens however the element is not clicked. I have tried various other xpaths and none worked. Here is the image for the Instagram source.

munyb
  • 27
  • 2
  • 7

3 Answers3

0

You can use below Xpath

.//*[@id='react-root']/section/main/article/div[2]/div[2]/p/a

or CSS Selector

.izU2O>a

or Link Text

Log in
Prany
  • 2,078
  • 2
  • 13
  • 31
0

try this code :

element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Log in")))
element.click()
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

This is what i tried on my local system and it worked

from selenium.webdriver.common.by import By
from selenium import webdriver
driver = webdriver.Chrome(executable_path="D:\\cs\\chromedriver.exe")
driver.get("https://www.instagram.com/")
a=driver.find_element(By.XPATH,'//a[text() = "Log in"]')
# added this step for compatibility of scrolling to the view
driver.execute_script("return arguments[0].scrollIntoView();", a)
a.click()

Corrected the XPATH and other changes.Please note executable path should be replaced with your path.

  • This worked! Thank you. I believe the issue was me needing to import By?... Appreciate it. – munyb Jun 06 '18 at 09:21