2015-11-05 48 views

回答

0

Selenium目前尚未支持以編程方式禁用Safari中的Cookie。你必須手動禁用它。您可以嘗試以下方法:

1.編寫將從Safari文件夾中刪除所有文件的代碼。事情是這樣的:

def clearCache(): 
    """This will just delete the files straight from the safari folder, guarentee a clean start""" 
    try: 
     #Using rm command assuming you are using MacOS 
     os.system("rm -rf $HOME/Library/Safari/LocalStorage/*.localstorage") 
    except Exception, e: 
     log.error("Error in clearCache: %s" %e) 

2.或者你也可以手動設置禁用cookie爲特定的配置文件,然後使用該配置文件來啓動你的Safari瀏覽器的webdriver。

Source

相關問題