Home > Enterprise >  Selenium find_elements function return Object (Selenium 4)
Selenium find_elements function return Object (Selenium 4)

Time:03-19

thank you for helping me.

I usually used Selenium 2,3 but today I try using Selenium 4 to use new features Relative Locators . I do a simple find expression but it always return weird Object like below

> print(driver.find_element(By.TAG_NAME, "a"))
{'ELEMENT': '0.4746792741017858-194'}

Or I find multiples

> print(driver.find_elements(By.TAG_NAME, "a"))
[{'ELEMENT': '0.4746792741017858-178'}, {'ELEMENT': '0.4746792741017858-179'}]

I expect it return WebDriver Object, but it doesn't Here is image of code and print statements. enter image description here Does anyone know this thing? Thank you so much!

CodePudding user response:

I ran your code

print(driver.find_element(By.TAG_NAME, "a"))

output on selenium 3:

<selenium.webdriver.remote.webelement.WebElement (session="251a91865546a6c66596a267e20688d1", element="a36e87f3-bf6a-475c-82e4-07e4febe0dc5")>

output on selenium 4:

[[ChromeDriver: chrome on WINDOWS (cbd87e312a3869b75a472d747371fd57)] -> tag name: a]

and your expectation :

I expect it return WebDriver Object, but it doesn't

Note that driver.find_element(By.TAG_NAME, "a") will always return a web element. It won't return a webdriver object.

on a web element you can perform .text, .send_keys, .click etc method

Update:

driver.get('https://www.google.com/')
driver.find_element(By.NAME, 'q').send_keys('etc')

CodePudding user response:

I finally found the asnwer for this issue. This is my set up:

chromedriver: 71.0.3578.80
chromebrowser: 99.0
selenium: 4

Basically, I'm using Selenium 4 which only support for above chromedriver: > 92. But my chromedriver v.71 -> outdate.

So that's why it's not compatible. So please check your chromedriver version if you choose selenium 4.

  • Related