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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃殌 Feature]: prefetching element properties #13929

Closed
kin4stat opened this issue May 11, 2024 · 6 comments
Closed

[馃殌 Feature]: prefetching element properties #13929

kin4stat opened this issue May 11, 2024 · 6 comments
Labels
G-w3c Requires change to W3C Spec

Comments

@kin4stat
Copy link

kin4stat commented May 11, 2024

Feature and motivation

For now, if you want to get any of element properties, selenium will send command to get this property which can take a lot of time, if you are processing a lot of elements:

Timer unit: 1e-06 s

Hits         Time  Per Hit   % Time  Line Contents
==================================================
3580   40481256.0  11307.6     53.4   element = driver.find_element(By.CSS_SELECTOR, get.selector)
3580       4323.0      1.2      0.0   if take_attribute:
1432   15983844.0  11161.9     21.1       text = element.get_attribute(attribute_name)
                                      else:
2148   18651709.0   8683.3     24.6       text = element.text

I think it would be useful to be able to prefetch some element properties to make processing it faster.

Usage example

element = driver.find_element(By.CSS_SELECTOR, get.selector, prefetch=[WebElement.text, WebElement.attribute("style")])
# using prefetched value
# time for execution == time for reading python object field
element.text
element.get_attribute("style")

or

element = driver.find_element(By.CSS_SELECTOR, get.selector, prefetch=[WebElement.text, WebElement.attributes])
# using prefetched value
# time for execution == time for reading python object field
element.text
element.get_attribute("style") 
element.get_attribute("class")
Copy link

@kin4stat, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@joerg1985
Copy link
Member

@kin4stat get_attribute is using a big javascript snippet (7kb since Selenium 4.17 and 43kb in older versions) to read the attribute. The get_dom_attribute / get_property method are using w3c commands and should be faster in theory.

@kin4stat
Copy link
Author

kin4stat commented May 11, 2024

@kin4stat get_attribute is using a big javascript snippet (7kb since Selenium 4.17 and 43kb in older versions) to read the attribute. The get_dom_attribute / get_property method are using w3c commands and should be faster in theory.

they are still making http request, which takes time to process(a little perfomance test above).

As i understand, these requests are not handled directly, they are placed to queue, and then worker thread processes this queue(inside chromium)

@joerg1985
Copy link
Member

My intention was to show an option to speed up your script, without waiting for a new feature. New features might take some time, especially when all drivers would need to implement them.

@kin4stat
Copy link
Author

My intention was to show an option to speed up your script, without waiting for a new feature. New features might take some time, especially when all drivers would need to implement them.

Maybe i would help with implementation inside chromium, for example, but i dont know, if the changes would be approved, because as i see, findelements is standardised in the w3c protocol

@diemol diemol added G-w3c Requires change to W3C Spec and removed I-enhancement needs-triaging labels May 13, 2024
Copy link

github-actions bot commented May 13, 2024

Hi, @kin4stat.
This issue has been determined to require a change to the
WebDriver W3C Specification or WebDriver BiDi W3C Specification for Selenium to be able to support it.

Please create an issue with the WebDriver project.

Feel free to comment on the issues that you raise back in this issue. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
G-w3c Requires change to W3C Spec
Projects
None yet
Development

No branches or pull requests

3 participants