ClericPy / ichrome

Chrome controller for Humans, based on Chrome Devtools Protocol(CDP) and python3.7+.
https://pypi.org/project/ichrome/
MIT License
227 stars 29 forks source link

how to change select value #144

Closed snja closed 8 months ago

snja commented 8 months ago

tag_region_sel = "#newUserCountry" await self.tab.querySelector(tag_region_sel, "value = 'US'")

after submit value not changed

ClericPy commented 8 months ago
import asyncio

from ichrome import AsyncChromeDaemon

async def main():
    async with AsyncChromeDaemon() as chrome:
        async with chrome.incognito_tab() as tab:
            await tab.goto("https://httpbin.org/forms/post", timeout=5)
            # print(await tab.html)
            tag = await tab.querySelector('[name="custname"]', 'value = "123"')
            await asyncio.sleep(0.5)
            await tab.alert(
                "watch the Customer name input node %s, %s" % (tag, tag.to_dict()),
                timeout=1000,
            )
            await asyncio.sleep(3)

asyncio.run(main())

see the demo, you need to make sure the #newUserCountry node is input tag, or you need tab.js run original JS code instead.

snja commented 8 months ago

i will change value of selectbox selector select#newUserCountry

ClericPy commented 8 months ago

try await tab.js("original Javascript")