Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to select option in select tag? #183

Open
sdv75 opened this issue Sep 4, 2024 · 5 comments
Open

How to select option in select tag? #183

sdv75 opened this issue Sep 4, 2024 · 5 comments

Comments

@sdv75
Copy link

sdv75 commented Sep 4, 2024

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
Copy link
Author

sdv75 commented Sep 5, 2024

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
Copy link
Author

sdv75 commented Sep 5, 2024

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
Copy link

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

@sdv75
Copy link
Author

sdv75 commented Sep 24, 2024

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
Copy link

Thank you this is working perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants