Search code examples
pythonseleniumfirefoxdebiangeckodriver

Is there a better solution than Selenium.title?


I'm trying to make an If/Else condition on the title of a specific webpage.

If the title is not 'You have been blocked', my script continue.
I've got an issue with selenium in python with different environment, in the first one (OSX) everything works. I can grab the title check if it contains specific string and continue or not my script. In Debian and headless mode activated, I can't access to the title of the web page.

driver.get(url)
print(driver.title)
if driver.title != 'You have been blocked':
   print('Ok have fun')
else:
   print('blocked')

It seems this function .title is very unstable, is there a better way to achieve it ? Thanks


Solution

  • I've found the right way to work with .title. Now my script wait the title of the webpage and and I parse it when it is loaded.

    
    wait = WebDriverWait(driver, 15)
    wait.until(EC.presence_of_element_located((By.TAG_NAME,"title")))
    if (driver.title != 'You have been blocked'):
        print('Ok Have Fun')
    else:
        print('Blocked')
    

    Thanks