在selenium-python中查找页面标题

Jay*_*lla 0 python selenium

我正在使用此方法在加载URL时刷新页面.

if driver.current_url == URL: driver.refresh()
Run Code Online (Sandbox Code Playgroud)

是否有我可以使用的API方法,以便如果页面标题与特定单词匹配,则driver.refresh()

Ade*_*lin 6

使用 driver.title

if "Python" in driver.title:
    driver.refresh()
Run Code Online (Sandbox Code Playgroud)

或者,ofc,严格平等:

if "Python" == driver.title:
    driver.refresh()
Run Code Online (Sandbox Code Playgroud)

作为提示,您可以driver通过将以下函数调用打印到控制台来检查其他内容:print(dir(driver)).你会看到这样的东西current_url,title,refresh等,并且可能节省您的时间.