omkarcloud / botasaurus

The All in One Framework to build Awesome Scrapers.
https://www.omkar.cloud/botasaurus/
MIT License
1.41k stars 128 forks source link

How to select option in select tag? #183

Open sdv75 opened 1 month ago

sdv75 commented 1 month ago

In Selenium it could be done like this:

select_item = driver.find_element(By.ID, "#some_id") Select(select_item).select_by_value(random_value)

How to do this in Botasaurus?

sdv75 commented 1 month ago

This code works well in URL https://www.etsy.com/listing/1256868877/vintage-pear-shaped-emerald-engagement with Selenium. el = driver.find_element(By.CSS_SELECTOR, 'select#variation-selector-0 option[value="2709528525"]') el.click()

I have been unable to find a solution to this problem in Botosaurus for 3 days now. When click(), nothing happens. When a human_click(), it does not find the element and throws an exception. js_run() does not work also.

Does anyone here ever answered?

sdv75 commented 1 month ago

Anybody help me!!! Botazaurus can't do a simple click on the select option. I've been suffering for three days already. I've already tried all the options

julienlepecheur commented 1 month ago

@sdv75 have you found a way to do it? I have the same problem after migrating to v4.

sdv75 commented 1 month ago
def js_select(num_id: str, option_value: str) -> str:
    return """
        var select = document.getElementById('variation-selector-""" + num_id + """');
        select.value = '""" + option_value + """';
        select.dispatchEvent(new Event('change'));
    """

driver.run_js(js_select(str(i), rnd_value))
julienlepecheur commented 1 month ago

Thank you this is working perfectly!