0

I am trying to scrape this website: http://sekolah.data.kemdikbud.go.id/ I want to select "Jenjang" field, "SMA" value. After that, need to click "Cari Sekolah" button enter image description here

Unfortunately, my code does not work. I manage to select SMA but then can't click "Cari Sekolah" to start the query. Anyone knows how to fix this. Here is my code:

from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import time
from selenium.webdriver.support.ui import Select

option = webdriver.ChromeOptions()
option.add_argument('--incognito')
webdriver = "/Users/rs26/Desktop/learnpython/web/chromedriver"
driver = Chrome(executable_path=webdriver, chrome_options=option)

url="http://sekolah.data.kemdikbud.go.id/"
driver.get(url)
wait = WebDriverWait(driver,15)
select_element = Select(driver.find_element_by_id("bentuk"))
select_element.select_by_value("SMA")
wait.until(EC.element_to_be_clickable((By.XPATH,"//button[text()='Cari Sekolah']"))).click()

2 Answers 2

1

Please find below solution to select from custom dropdown

 from selenium import webdriver
    from selenium.webdriver.support.ui import Select
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait

    # # Solution 1:
    driver = webdriver.Chrome(executable_path=r"C:\New folder\chromedriver.exe")
    driver.get('http://sekolah.data.kemdikbud.go.id/')
    driver.maximize_window()
    element =  WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "select2-bentuk-container")))
    element.click()
    list=WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='select2-search__field']")))
    list.send_keys("SMA")
    select=WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "select2-results__option")))
    select.click()

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks a lot unfortunately the send keys doesnt work. It managed to click the drop down but couldnt select SMA.
@rs26: what issue you are facing because I have already verified solution & its working fine for me
Thanks Dipak. Your code allows me to click the dropdown, but then it stops there and doesnt select "SMA". This is the error: WebDriverException: unknown error: call function result missing 'value'
Please try to copy entire solution it's a custom drop down we are sending input value SMA and after that based on class name we are selecting it from list
Does it have to do with my chrome? the problem is: WebDriverException: disconnected: unable to connect to renderer (Session info: chrome=80.0.3987.162) (Driver info: chromedriver=2.31.488774 (7e15618d1bf16df8bf0ecf2914ed1964a387ba0b),platform=Mac OS X 10.12.6 x86_64)
|
0

You can use form button[type=submit] css selector to click.

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"form button[type=submit]"))).click()

1 Comment

Thanks Sers. The problem is with the dropdown selection because the program stops there. The error is: WebDriverException: unknown error: call function result missing 'value' The submit button works fine on its own.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.