简体   繁体   中英

Selenium chromedriver error_TyperError

I am getting following error. Can someone assist me

from selenium import webdriver

headlessoptions = webdriver.ChromeOptions()
headlessoptions.add_argument('headless')
chromedriver = 'C:/dev_python/Webdriver/chromedriver.exe'
driver = webdriver.Chrome(chromedriver, options=headlessoptions)
driver.get('https://davelee-fun.github.io/')

elem = driver.find_element_by_tag_name("h1")
print (elem.text)
    
driver.quit()

why error come?

Your line, elem = driver.find_element_by_tag_name("h1") , is going to cause an error because Selenium just removed that method in version 4.3.0 . See the CHANGES: https://github.com/SeleniumHQ/selenium/blob/a4995e2c096239b42c373f26498a6c9bb4f2b3e7/py/CHANGES

Selenium 4.3.0
* Deprecated find_element_by_* and find_elements_by_* are now removed (#10712)
* Deprecated Opera support has been removed (#10630)
* Fully upgraded from python 2x to 3.7 syntax and features (#10647)
* Added a devtools version fallback mechanism to look for an older version when mismatch occurs (#10749)
* Better support for co-operative multi inheritance by utilising super() throughout
* Improved type hints throughout

You now need to use the following in your example:

elem = driver.find_element("tag name", "h1")

For improved reliability, you should consider using WebDriverWait in combination with element_to_be_clickable .

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