Instagram search bar with selenium

匿名 (未验证) 提交于 2019-12-03 01:10:02

问题:

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 have already seen some posts about that but they did not 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 can I correct that ?

回答1:

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

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

I have modified your code.

Code Snippet:

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") 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!