botasaurus icon indicating copy to clipboard operation
botasaurus copied to clipboard

How to select option in select tag?

Open sdv75 opened this issue 1 year ago • 5 comments

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 avatar Sep 04 '24 19:09 sdv75

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 avatar Sep 05 '24 08:09 sdv75

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

sdv75 avatar Sep 05 '24 17:09 sdv75

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

julienlepecheur avatar Sep 23 '24 19:09 julienlepecheur

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))

sdv75 avatar Sep 24 '24 13:09 sdv75

Thank you this is working perfectly!

julienlepecheur avatar Sep 24 '24 14:09 julienlepecheur

added this feautre

Chetan11-dev avatar Apr 11 '25 09:04 Chetan11-dev