SeleniumHQ / seleniumhq.github.io

Official Selenium website and documentation
https://selenium.dev
Apache License 2.0
1.09k stars 1.28k forks source link

[py] BiDi APIs for python That's too bad #800

Open defnngj opened 2 years ago

defnngj commented 2 years ago

🐛 Bug Report

https://www.selenium.dev/documentation/webdriver/bidi_apis/

Python(selenium) has no driver.register() --- this is bug?

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
async with driver.log.mutation_events() as event:
    pages.load("dynamic.html")
    driver.find_element(By.ID, "reveal").click()
    WebDriverWait(driver, 5)\
        .until(EC.visibility_of(driver.find_element(By.ID, "revealed")))

assert event["attribute_name"] == "style"
assert event["current_value"] == ""
assert event["old_value"] == "display:none;"

Python(selenium) has no dirver.log How is pages defined?

I tried to modify the code as follows:

import asyncio
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.log import Log
from selenium.webdriver.support import expected_conditions as EC

async def demo():
    driver = webdriver.Chrome()
    session = driver.bidi_connection()
    log = Log(driver, session)

    async with log.mutation_events() as event:
        driver.get("https://www.google.com")
        driver.find_element(By.ID, "reveal").click()
        WebDriverWait(driver, 5)\
            .until(EC.visibility_of(driver.find_element(By.ID, "revealed")))

    assert event["attribute_name"] == "style"
    assert event["current_value"] == ""
    assert event["old_value"] == "display:none;"

asyncio.run(demo())

running error:

Traceback (most recent call last):
  File "D:/github/test-circle/selenium4/code/demo.py", line 25, in <module>
    asyncio.run(demo())
  File "C:\Python38\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "D:/github/test-circle/selenium4/code/demo.py", line 12, in demo
    log = Log(driver, session)
  File "C:\Python38\lib\site-packages\selenium\webdriver\common\log.py", line 48, in __init__
    self.session = bidi_session.session
AttributeError: '_AsyncGeneratorContextManager' object has no attribute 'session'
Must asyncio be used? Why provide asyncio examples, and incomplete?

Must asyncio be used? Why provide asyncio examples, and incomplete?

To Reproduce

null

Expected behavior

null

Test script or set of commands reproducing this issue

null

Environment

OS: Windows 10 Browser: Chrome Browser version: selenium 4.0 Browser Driver version: ChromeDriver 2.43, Language Bindings version: python Selenium Grid version (if applicable): 4.0

diemol commented 2 years ago

Thank you for the feedback, you are right, examples should be more complete. I will move this to the website and docs repo.

JVPyDev commented 2 years ago

Any updates on this?

symonk commented 2 years ago

I will fix the documentation for mutability observations this evening after work; yes async must be used and the examples are most likely based on some sort of fixtures (which imo is fine) w/r/t pages. p.s not sure if it relies on trio i haven't looked into it yet

alperenb commented 2 years ago

has this been fixed?

diemol commented 2 years ago

I am guessing the example was copied and pasted from https://github.com/SeleniumHQ/selenium/blob/41dce806c9ac825b69da149dad4725e78f5adda1/py/test/selenium/webdriver/common/bidi_tests.py#L65, let me figure that one out and get back to you all.