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

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

Open
defnngj opened this issue Oct 13, 2021 · 5 comments
Open

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

defnngj opened this issue Oct 13, 2021 · 5 comments
Labels
code-python Fix code example in Python

Comments

@defnngj
Copy link

defnngj commented Oct 13, 2021

🐛 Bug Report

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

  • Register Basic Auth

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

  • Mutation Observation
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
Copy link
Member

diemol commented Oct 13, 2021

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

@diemol diemol transferred this issue from SeleniumHQ/selenium Oct 13, 2021
@JVPyDev
Copy link

JVPyDev commented Oct 26, 2021

Any updates on this?

@symonk
Copy link
Member

symonk commented Nov 11, 2021

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

has this been fixed?

@titusfortner titusfortner added the code-python Fix code example in Python label Jan 11, 2022
@diemol
Copy link
Member

diemol commented Aug 19, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-python Fix code example in Python
Projects
None yet
Development

No branches or pull requests

7 participants