HENNGE / arsenic

Async WebDriver implementation for asyncio and asyncio-compatible frameworks
Other
349 stars 52 forks source link

get_rect exception #69

Closed cyberbudy closed 3 years ago

cyberbudy commented 5 years ago

get_rect is raising an exception when the value is 607.984px

raise ValueError(f"{original!r} is not an int or <int>px value")
mralecthomas commented 4 years ago

The built in Python function isdigit() that is found in utils.py is expecting an integer instead of the float that you are passing.

Round up your pixel value that you are passing into get_rect with math.ceil and it will fix your issue.

cyberbudy commented 4 years ago
    async def get_rect(self):
        data = await self._request(url="/rect", method="GET")
        return Rect(data["x"], data["y"], data["width"], data["height"])

This is get_rect method of Element. Where should I round pixel value?

I'm calling this method on found Element, something lile:

element = await session.get_element("#my-selector")
# Exception is raised here
element.get_rect()
mralecthomas commented 4 years ago

You can try modifying your px_to_int() method in utils.py to the following:

def px_to_int(value: str) -> int:
    original = value
    if value.endswith("px"):
        value = value[:-2]
    value = math.ceil(value)
    if value.isdigit():
        return int(value)
    else:
        raise ValueError(f"{original!r} is not an int or <int>px value")

Don't forget to add:

from math import ceil
cyberbudy commented 4 years ago

Do you mean a pull request with your modification?

ojii commented 3 years ago

fixed in 20.9