Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python selenium find_element_by_css_selector() not working

from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.google.com')
content = driver.find_element_by_css_selector('title')
print content

I can't seem to get any content by any means(tag_name, class_name, name...) What is the problem with this code?

like image 303
Rastko Jović Avatar asked Apr 25 '26 04:04

Rastko Jović


1 Answers

There doesn't seem to be any problem with the code. The is element being identified correctly by your code.

content = driver.find_element_by_css_selector('title')
print content.tag_name

This should confirm that you have indeed located a web element with title tag. The content.text does not return anything since the title element is not part of the page itself. (Similar trouble discussed here in Java)

If you're trying to print the title of the page, use the following driver field

print(driver.title)
like image 50
Obsidian Avatar answered Apr 28 '26 00:04

Obsidian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!