Reputation: 193
im trying to scrape table based on dates from this site https://www.bi.go.id/id/statistik/informasi-kurs/transaksi-bi/Default.aspx with this code
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
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.common.exceptions import TimeoutException
import re
import time
from bs4 import BeautifulSoup
# Import webdriver to initialise a browser
from selenium.webdriver import ActionChains
import csv
import pandas as pd
import requests
driver = webdriver.Chrome()
driver.get("https://www.bi.go.id/id/statistik/informasi-kurs/transaksi-bi/Default.aspx")
wait = WebDriverWait(driver, 10)
# click "usd"
book = wait.until(
EC.element_to_be_clickable((By.XPATH,' //*[@id="selectPeriod"]/option[range]'))
)
book.click()
book1 = wait.until(
EC.element_to_be_clickable((By.XPATH,' //*[@id="ctl00_PlaceHolderMain_g_6c89d4ad_107f_437d_bd54_8fda17b556bf_ctl00_ddlmatauang1"]/option[USD]'))
)
book1.click()
start_date = driver.find_element_by_id("ctl00_PlaceHolderMain_g_6c89d4ad_107f_437d_bd54_8fda17b556bf_ctl00_txtFrom")
start_date.send_keys("20-Nov-15")
end_date = driver.find_element_by_id("ctl00_PlaceHolderMain_g_6c89d4ad_107f_437d_bd54_8fda17b556bf_ctl00_txtTo")
end_date.send_keys("20-Nov-20")
submit_button = driver.find_element_by_id("ctl00_PlaceHolderMain_g_6c89d4ad_107f_437d_bd54_8fda17b556bf_ctl00_btnSearch1").click()
but instead i got this error and i dont know why.can anybody help me what goes wrong?
--------------------------------------------------------------------------- TimeoutException Traceback (most recent call last) in 9 10 ---> 11 book = wait.until( 12 EC.element_to_be_clickable((By.XPATH,' //*[@id="selectPeriod"]/option[range]')) 13 )
~\anaconda3\lib\site-packages\selenium\webdriver\support\wait.py in until(self, method, message) 78 if time.time() > end_time: 79 break ---> 80 raise TimeoutException(message, screen, stacktrace) 81 82 def until_not(self, method, message=''):
TimeoutException: Message:
Upvotes: 0
Views: 739
Reputation: 9969
This should work since it's a Select tag.
driver.get("https://www.bi.go.id/id/statistik/informasi-kurs/transaksi-bi/Default.aspx")
wait = WebDriverWait(driver, 10)
book = wait.until(EC.element_to_be_clickable((By.ID,"selectPeriod")))
sel = Select(book)
sel.select_by_value("range")
Import
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
Upvotes: 0