简体   繁体   中英

Find elements on Python Selenium - one element short

I am seeing a very odd bug on the function "find_elements_by_css_selector" on selenium. Applying a selector that should return 10 elements it returns 9 instead, consistently on all different page examples I tried. Same selector I tested with javascript "querySelectorAll" and indeed returned 10, so the css selector works fine.

Anyone had this "one element short" bug too?

Here's the test:

css = 'a[href]' # your css goes here
elements = driver.find_elements_by_css_selector(css)
print(len(elements))

elements = driver.execute_script("""
  return [...document.querySelectorAll(arguments[0])]
""", css)
print(len(elements))

I'd be interested to hear if the numbers are really different. If so, you found a bug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM