python - 使用 Selenium 在 Instagram 的搜索栏中输入内容

标签 python selenium selenium-webdriver css-selectors instagram

我正在尝试使用 python 中的 selenium Web 驱动程序选择一个搜索栏。问题是类名和许多 css 值是动态生成的。选择搜索栏提交搜索的最佳方式是什么?

当我检查时,搜索栏是动态的:

Search Bar Screenshot

最佳答案

假设“placeholder="Search"”位始终相同,那么您可以这样做:

from selenium import webdriver
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.Firefox()
driver.get("http://www.python.org")

searchbox = WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located(
        (By.XPATH, "//input[@placeholder='Search']")
    )
)

根据字段上设置的属性通过 XPATH 获取元素。

关于python - 使用 Selenium 在 Instagram 的搜索栏中输入内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36876428/

相关文章:

python-3.x - 忽略或解决机器人框架中测试自动化的证书警告

python - 如何通过 Selenium 根据 url 将文本发送到地理位置搜索框

python - 从嵌套字典打印

python查找换行符是否在字符串中

python - pip使用Python 2.5并且需要使用Python 2.7

python - 使用自定义信息填写日历

python - 使用 selenium 和 phantomJS 切换框架

javascript - 使用 webdriverjs 和 mocha/chai 等待页面加载

selenium - 如何使用 selenium webdriver 在客户端启动浏览器

Python 在向 numpy 数组添加过程中从 long 进行转换