I am having trouble setting a value in a combobox using selenium. The find_element_by_xpath statement is failing to locate the combobox by class or ng-model. Specifically, I am attempting to change the time period for a stock from one day to one week.
Here is the relevant javascript code on the webpage:
**<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>
Here is the code I have attempted:
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()**
However, this results in the following error:
Error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//select[@class='ng-valid ng-dirty ng-valid-parse user-success ng-touched']/option[text()='ONE_WEEK']"} (Session info: chrome=79.0.3945.130)
I also tried searching with driver.find_element_by_xpath("//select[@ng-model='analysisGraph.periodselector.period']/option[text()='ONE_WEEK']").click()
I am a beginner Python programmer, can anyone spot any obvious errors?