0

I want to search a special keyword in Instagram. For example, I want to search this word:"internet". I can send this key in search box. But, when I use submit method in Selenium by Python3, it doesn't work and give me error. This is my code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Firefox()
url="https://www.instagram.com/p/pTPI-kyX7g/?tagged=resurant"
driver.get(url)

#login_button=driver.find_element_by_xpath("""/html/body/span/section/main/article/div[2]/div[2]/p/a""")
#login_button.click()
import time
driver.implicitly_wait(5)
search_button=driver.find_element_by_xpath("""/html/body/span/section/nav/div[2]/div/div/div[2]/input""")
search_button.send_keys("internet",Keys.RETURN)

This is no anu error, but it dosen't work.

  • Possible duplicate of [how to press enter in selenium python?](https://stackoverflow.com/questions/49178236/how-to-press-enter-in-selenium-python) – undetected Selenium Mar 08 '18 at 19:21
  • There are different. In contrary to your sent link, my code has no any error, but, it doesn't work –  Mar 08 '18 at 19:37
  • Are you looking to browse the first result of a search in detail? This is exact behavior if you do this for yourself in instagram. – Oluwafemi Sule Mar 08 '18 at 20:54

3 Answers3

0

Have you tried

 searchbox     driver.find_element_by_xpath( Xpath/locator for search box).sendKey("internet")    
 search button driver.find_element_by_xpath(Xpath/locator for the search key button).click

which is you send the "internet" to that edit Box first then looking for that search button and perform .click not input the search text and send the key at sametime

0

Use this solution please:

time.sleep(5)
search_button.send_keys(u'\ue007')
search_button.send_keys(u'\ue007')
Hamed Baziyad
  • 1,954
  • 5
  • 27
  • 40
0

By this code enter will be pressed, but, after pressing and loading page an error will be occurred:

search_button.send_keys("internet")
    while True:
        search_button.send_keys(u'\ue007')
Hamed Baziyad
  • 1,954
  • 5
  • 27
  • 40