kaliiiiiiiiii / Selenium-Driverless

undetected Selenium without usage of chromedriver
https://kaliiiiiiiiii.github.io/Selenium-Driverless/
Other
487 stars 61 forks source link

[BUG] click on selectors fails #94

Open miltonvo opened 10 months ago

miltonvo commented 10 months ago

Hi for all

im trying to find this input field:

input_element = await self.driver.find_element(By.CSS_SELECTOR, ".bsf-StakeBox_StakeValue.bsf-StakeBox_StakeValue-input.bsf-StakeBox_StakeValue-empty")

and then write some value

await input_element.write(str(self.user_config.goal_value))

i see the script writing on field the value but if i click on another place the value disappears

thanks for if someone can helps to solve this

kaliiiiiiiiii commented 10 months ago

Thanks for submitting this issue. I'm working on a cross-platform patch for this. Still will take some time tho:)

UPDATE

can be used for selecting elements (headfull is undetectable only) for now. Will be implementing it propperly at some point

https://github.com/kaliiiiiiiiii/Selenium-Driverless/blob/882c46354db3652a9dd26d36a386c84ed1b4f4d6/tests/html/test_select.py#L107-L160

usage:

from cdp_patches.input import AsyncInput
from selenium_driverless.types.by import By

# other imports, setting up driver etc...

async_input = await AsyncInput(browser=driver)
select_elem = await driver.find_element(By.XPATH, '//select[@id="animals') # or the respective query for finding the element
await select(select_elem, value="dog", async_input=async_input) # or text="Dog"

previous UPDATE:

as now, select dropdowns are broken due to crbug#1503393. You can use something like the following for that:

value = "audi"
select = await driver.find_element(By.XPATH, '//select[@id="cars"]', timeout=5)
await asyncio.sleep(1)
await select.execute_script('''
    var evt = new Event("change")
    evt.initEvent("change", true, true)
    obj.value = arguments[0]
     obj.dispatchEvent(evt)
    ''',  value)

where the value is the value for the specified option (doesn't have to be same as the text!) image (source page for image)

Note: While this works, it's easely detectable.

miltonvo commented 10 months ago

Excelent, thanks

solved with simulating sending keys and write value with javascript :)

Bonfahh commented 10 months ago

@miltonvo can you explain more about your solution ?

Bonfahh commented 10 months ago

I'm having the same problem here

gembleman commented 10 months ago

example

driver.execute_script("document.getElementById('FIND ELEMENT').value = arguments[0]", Your Argument)
kaliiiiiiiiii commented 10 months ago

example

driver.execute_script("document.getElementById('FIND ELEMENT').value = arguments[0]", Your Argument)

you can pass WebElements as an argument directly as well. Any js like that will be detectable tho.

Bonfahh commented 10 months ago

Yeah, it doesn't work, changing the value or innerhtml even though the appearing text change it doesn't update the button that is disabled without a value

tankow79 commented 9 months ago

Hi friends, this is what worked for me

dropdown_element = driver.find_element(By.XPATH, "FIND ELEMENT")  # find the dropdown
dropdown_element.click()  # click the dropdown
driver.execute_script(f"arguments[0].value = '{random.randint(1, 12)}';", dropdown_element)  # I choose a random element
driver.execute_script("arguments[0].dispatchEvent(new Event('change', { bubbles: true }));", dropdown_element) # I confirm the selection of the item
kaliiiiiiiiii commented 9 months ago

Hi friends, this is what worked for me

dropdown_element = driver.find_element(By.XPATH, "FIND ELEMENT")  # find the dropdown
dropdown_element.click()  # click the dropdown
driver.execute_script(f"arguments[0].value = '{random.randint(1, 12)}';", dropdown_element)  # I choose a random element
driver.execute_script("arguments[0].dispatchEvent(new Event('change', { bubbles: true }));", dropdown_element) # I confirm the selection of the item

Yeah "works" sure. But detectable as well.

asliazas commented 8 months ago

Excelent, thanks

solved with simulating sending keys and write value with javascript :)

Could you share the solution? I'm interested as well :)

ImWez commented 6 months ago

any undetectable solution?