selenium
selenium copied to clipboard
[🚀 Feature]: prefetching element properties
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")
@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!
@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
get_attributeis using a big javascript snippet (7kb since Selenium 4.17 and 43kb in older versions) to read the attribute. Theget_dom_attribute/get_propertymethod 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)
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.
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
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.
This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.