How to automate the Instagram search bar with selenium

0 votes

I am working on a program that can type something in the Instagram search bar. Here is the code of the website:

<input class="XTCLo x3qfX " placeholder="Rechercher" value="" type="text">

I've already looked into a few posts about that but none of them work with me. Here is my code:

input_search = wait(browser, 10).until(
EC.visibility_of_element_located(
    (By.XPATH, "//input[@placeholder='Rechercher']")
))
action=ActionChains(browser)
action.move_to_element(input_search)
action.send_keys(search)
action.click()
action.perform()

how do I correct that?

Mar 8, 2019 in Selenium by Vaishnavi
• 1,180 points
2,007 views

1 answer to this question.

+1 vote

Hi, please don't search by any placeholder text as it will change the browser language. You should use the locator which will be consistent with all browser languages.

In your case, if the browser language is English, then placeholder text will be "Search".

I have modified your code.

input_search = wait(browser, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[contains(@class,'XTCLo')]")))
input_search.click()
input_search.send_keys("search")

Hope this helps! :)

answered Mar 8, 2019 by Surya
• 970 points
how can I press 'Enter' after I typed the search?
You could implement "Enter" using send_keys(Keys.ENTER)

Related Questions In Selenium

0 votes
3 answers

How to click the search button using Selenium web driver and Python

You can try with tag. #this code will ...READ MORE

answered Apr 10, 2019 in Selenium by Matin
9,921 views
0 votes
1 answer

Is it possible to automate the captcha and bar-code reader using Selenium?

Hey Ruhi, it’s not possible to automate ...READ MORE

answered Jun 4, 2019 in Selenium by Umang
529 views
0 votes
1 answer
0 votes
0 answers
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
3,580 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,583 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,623 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,923 views
0 votes
1 answer

How to check if an image is displayed on web page while working with Selenium WebDriver?

I've come across a similar situation before, where the image ...READ MORE

answered May 10, 2019 in Selenium by Surya
• 970 points
3,358 views
0 votes
1 answer

How to get the select options using Selenium WebDriver in Java

Hey there! You should be able to get ...READ MORE

answered Jun 13, 2019 in Selenium by Surya
• 970 points
1,577 views