0

Still working on this Instagram problem, i really need your help.

Here is my code:

input_button = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
'//button[@class ="chBAG"]')))

action=ActionChains(browser)
action.move_to_element(input_button)
action.click()
action.perform()

Here is the HTML:

<button class="chBAG">Fermer</button>

But I got a:

selenium.common.exceptions.TimeoutException: Message: 

Could someone help me solve that problem ?

Thx

5
  • And stackoverflow.com/questions/50845863/… Commented Jun 17, 2018 at 7:54
  • 1
    It's not the same thing here it's with a button and by the way nobody help me solve the search bar problem so before saying that's a duplicate could you help me solve it and like that i can edit the other one Commented Jun 17, 2018 at 7:54
  • 1
    You didn't post the relevant html and only one line of the exception. There isn't much we can help you with. I'm guessing the elements inside a <frame>, but it's just a guess. Commented Jun 17, 2018 at 7:57
  • I edit it with the post with the html so you could help me ;) Commented Jun 17, 2018 at 8:00
  • Here is the link: instagram.com/accounts/login and my goal is to conect on the account (done and it work) then to close a pop up windows and then to search something in the research bar Commented Jun 17, 2018 at 12:50

2 Answers 2

0

As per your requirement, you can use this code :

It'll search for "This is testing" string in search bar of Instagram.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 

driver = webdriver.Chrome(executable_path = r'D:/Automation/chromedriver.exe')
driver.get("https://www.instagram.com/accounts/login/")

username = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "username")))

password = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "password")))

username.send_keys("your username")
password.send_keys("your password")
driver.find_element_by_tag_name('button').click()

search = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//span[text()='Search']")))

search.click()
driver.find_element_by_xpath("//div[@role='dialog']/preceding-sibling::input").send_keys("This is testing")
Sign up to request clarification or add additional context in comments.

1 Comment

Can you please give the update on this ?
0

You are getting this error because of generic class of input fields. Every time you open the page the classes names will be generated randomly. So how to fix it? For example like this:

imagine you want to log in, you have to:

  1. click on email input field
  2. type information
  3. click on password input field
  4. type information
  5. click on Log in button

The sample code could be like this:

# xpath will work every time because it is static
email_input = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
'//form/div[1]/div/div/input'))) # locate email input
email_input =ActionChains(browser)
email_input.move_to_element(email_input)
email_input.click()
email_input.sendKeys("email")
email_input.perform()

password_input = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
'//form/div[2]/div/div/input'))) # locate password input
password_input =ActionChains(browser)
password_input.move_to_element(password_input)
password_input.click()
email_input.sendKeys("password")
password_input.perform()

login_button = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
'//span/button'))) # locate login button
login_button_action=ActionChains(browser)
login_button_action.move_to_element(login_button )
login_button_action.click()
login_button_action.perform()

To search something in search bar you have to do this:

  1. click on search input field
  2. type information
  3. wait until results will load
  4. click on the one of the results

Code:

import time # will be need below

search_input = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
"//input[@placeholder = 'Search']"))) # locate search input
search_input =ActionChains(browser)
search_input.move_to_element(search_input)
search_input.click()
search_input.sendKeys("fermer")
search_input.perform()

time.sleep(5) # wait 5 seconds until dropdown will appear

dropdown_menu = wait(browser,10).until(EC.element_to_be_clickable((By.XPATH, 
"//a[@href = '/explore/tags/fermermaid/']"))) # locate fermeraid
dropdown_menu = ActionChains(browser)
dropdown_menu.move_to_element(dropdown_menu)
dropdown_menu.click()
dropdown_menu.perform()

Comments