【发布时间】:2021-10-22 23:28:34
【问题描述】:
我正在尝试打开浏览器并在搜索输入框中输入搜索项并执行回车。
我能够打开浏览器并能够在搜索框中输入搜索关键字,但我无法执行输入。此外,当我输入关键字时,我得到的建议列表很少,我无法选择第一项。我不确定代码出了什么问题。
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.common.by import By
browser = webdriver.Firefox()
browser.get("https://www.tickertape.in/stocks/")
browser.maximize_window()
inputElement=browser.find_element_by_id('search-stock-input')
inputElement.click()
inputElement.send_keys('Reliance industries')
inputElement.click()
我尝试了以下两个选项来单击/输入列表,但我无法选择/输入它。
inputElement = wait(browser, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.Select-option#"react-autowhatever-1-section-0-item-1')))
inputElement.click()
actions = ActionChains(browser)
actions.move_to_element(inputElement).click().send_keys('Reliance industries')
actions.perform()
这是 HTML。
//*[@id="search-stock-input"]
<input type="search" value="Reliance Industries" autocomplete="off" aria-autocomplete="list" aria-controls="react-autowhatever-1" class="jsx-4060663325 stock-input-box full-width" placeholder="Search stocks, indices, ETFs, Mutual Funds or brands" maxlength="80" id="search-stock-input" aria-label="search text">
<div id="react-autowhatever-1" role="listbox" class="jsx-513088474 jsx-507199909 jsx-145021258 react-autosuggest__suggestions-container"><ul class="jsx-513088474 jsx-507199909 jsx-145021258 d-flex tags-list"></ul><div class="jsx-513088474 jsx-507199909 jsx-145021258 assets-suggestion-container "></div></div>
提前致谢
【问题讨论】:
-
我会做的,因为我不知道我需要接受答案。我会检查指南。
-
如果我的回答对你有用,请告诉我
-
网络浏览器正在打开,但没有搜索到关键字,并且没有打开特定关键字搜索的站点。
-
当然,我的代码缺少一些您已经拥有的代码。将更新它以使其清晰
-
网页仍在打开,但没有搜索到关键字,并且特定关键字站点未打开。执行代码后,我得到以下日志。
标签: python-3.x selenium-webdriver css-selectors selenium-firefoxdriver