我正在尝试使用Selenium在组合框中设置一个值。但是find_element_by_xpath语句无法按类或ng-model找到组合框(详细来说,我试图将股票的时间段从一天改为一周)
web页面包含我正在搜索的元素的以下javascript
**<select ng-model="analysisGraph.periodselector.period" class="ng-valid ng-dirty ng-valid-parse user-success ng-touched">**
<!-- ngIf: !analysisGraph.periodselector.dayOnly -->
<option ng-if="!analysisGraph.periodselector.dayOnly" value="INTRADAY" class="ng-binding ng-scope">Intradag</option><!-- end ngIf: !analysisGraph.periodselector.dayOnly --><!-- ngIf: !analysisGraph.periodselector.dayOnly -->
<option ng-if="!analysisGraph.periodselector.dayOnly" value="ONE_WEEK" class="ng-binding ng-scope">1 uke</option><!-- end ngIf: !analysisGraph.periodselector.dayOnly -->
<option value="ONE_MONTH" class="ng-binding">1 mnd</option><!-- ngIf: !analysisGraph.periodselector.hideOption.hide3m -->
<option ng-if="!analysisGraph.periodselector.hideOption.hide3m" value="THREE_MONTHS" class="ng-binding ng-scope">3 mnd</option><!-- end ngIf: !analysisGraph.periodselector.hideOption.hide3m --><!-- ngIf: !analysisGraph.periodselector.hideOption.hide6m -->
<option ng-if="!analysisGraph.periodselector.hideOption.hide6m" value="SIX_MONTHS" class="ng-binding ng-scope">6 mnd</option><!-- end ngIf: !analysisGraph.periodselector.hideOption.hide6m -->
<option value="YTD" class="ng-binding">YTD</option><!-- ngIf: !analysisGraph.periodselector.hideOption.hide1y -->
<option ng-if="!analysisGraph.periodselector.hideOption.hide1y" value="ONE_YEAR" class="ng-binding ng-scope">1 år</option><!-- end ngIf: !analysisGraph.periodselector.hideOption.hide1y --><!-- ngIf: !analysisGraph.periodselector.hideOption.hide3y -->
<option ng-if="!analysisGraph.periodselector.hideOption.hide3y" value="THREE_YEARS" class="ng-binding ng-scope">3 år</option><!-- end ngIf: !analysisGraph.periodselector.hideOption.hide3y --><!-- ngIf: !analysisGraph.periodselector.hideOption.hide5y -->
<option ng-if="!analysisGraph.periodselector.hideOption.hide5y" value="FIVE_YEARS" class="ng-binding ng-scope">5 år</option><!-- end ngIf: !analysisGraph.periodselector.hideOption.hide5y --><!-- ngIf: hasLaunchData -->
</select>
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from bs4 import BeautifulSoup
import pymysql
import ose_data
chrome_options = Options()
driver = webdriver.Chrome(executable_path='chromedriver', options=chrome_options)
driver.get('https://www.oslobors.no/markedsaktivitet/#/details/ADE.OSE/overview')
time.sleep(5)
bs = BeautifulSoup(driver.page_source, 'html.parser')
**driver.find_element_by_xpath("//select[@class='ng-valid ng-dirty ng-valid-parse user-success ng-touched']/option[text()='ONE_WEEK']").click()**
我还尝试了使用driver.find_element_by_xpath(“//select[@ng-model='analysisgraph.periodselector.period']/option[text()='one_week']”)进行搜索。click()
对于同样的错误,有人看到任何来自noob Python程序员的重大错误吗?:)
Xpath是错误的,请使用select[ng-model=“analysisgraph.periodselector.period”]
css选择器获取元素。该元素是一个带有select标记的下拉列表,要选择它,请使用select
类。添加了WebDriverWait
,以便在与元素交互之前等待元素可单击。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from bs4 import BeautifulSoup
import pymysql
import ose_data
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
chrome_options = Options()
driver = webdriver.Chrome(executable_path='chromedriver', options=chrome_options)
driver.get('https://www.oslobors.no/markedsaktivitet/#/details/ADE.OSE/overview')
wait = WebDriverWait(driver, 10)
# bs = BeautifulSoup(driver.page_source, 'html.parser')
details_period = Select(wait.until(
EC.element_to_be_clickable((By.CSS_SELECTOR, 'select[ng-model="analysisGraph.periodselector.period"]'))))
details_period.select_by_value('ONE_WEEK')
# You can also use
# details_period.select_by_visible_text()
# details_period.select_by_index()
问题内容: 为了将GUI窗口小部件的数量保持在最低水平,我需要找到一种方法让用户选择下拉菜单项,这些菜单项可用于过滤listWidget项中显示的内容。假设listWidget列出了5种不同的项目类别:“猫A”,“猫B”,“猫C”,“猫D”,“猫E”。我可以为每个商品类别实现单选或复选框。但是5个单选按钮或复选框会占用大量GUI空间。带有可检查项的组合框似乎是正确的选择。有任何想法吗? 问题答案:
我有包含以下模式的文档的集合。我想过滤/查找所有包含性别女性的文档并汇总大脑评分的总和。我尝试了下面的语句,它显示了无效的管道错误。 架构:
我正在尝试设置组合框的文本颜色。 我尝试的代码
假设我有以下html代码: 这是一个组合框 当前已选择值MyDivision。 使用Selenium WebDriver我试图获得选定的值,但没有成功。 我尝试了: 但这会返回组合框中的所有值。 请帮忙? 编辑:
有人知道解决这个问题的办法吗?我已经测试了在Modulepath和classpath中添加来自Selenium的外部jar。然而,两者似乎有相同的结果和错误。
我正在创建一个影院系统,用户可以通过主页中的组合框选择电影。我在FilmController类中创建了一个数组列表,然后将其转换为observableList,并且正在努力将其内容填充到combobox(HomepageController)中。 这是arraylist的FilmController 我尝试在HomepageController中实现此功能,但它似乎给了我一个错误: 我已经研究过这