Selenium webdriver无法在默认的chrome配置文件中打开网站

时间:2018-02-19 07:33:51

标签: python selenium-webdriver selenium-chromedriver

我在Python中尝试过selenium webdriver,它运行正常。但是当我尝试打开默认的chrome配置文件时,它不会打开网站。

代码是

func postVideoToYT(videoUrl: URL, token: String,title:String,innoId:Int,videoTags:String,callback: @escaping (Bool) -> Void) {
        do {
            let headers = ["Authorization": "Bearer \(token)"]
            let videoData = try Data(contentsOf: videoUrl)
            upload(multipartFormData: { multipartFormData in
                multipartFormData.append("{'snippet':{'title' : '\(title)', 'description': ''}}".data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: "snippet", mimeType: "application/json")
                multipartFormData.append("{'status' : {'privacyStatus':'unlisted'}}".data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: "status",mimeType: "application/json")
                multipartFormData.append(videoData, withName: "video", fileName: "video.mp4", mimeType: "application/octet-stream")
            }, usingThreshold: 1, to: URL(string: "https://www.googleapis.com/upload/youtube/v3/videos?part=snippet&status")!, method: .post, headers: headers, encodingCompletion: { encodingResult in
                switch encodingResult {
                case .success(let upload, _, _):

                    upload.responseJSON { response in
                        print("Post video to url --->\(response)")
                        if let json = response.result.value as? [String : Any] {
                            let videoId = json["id"] as! String
                            self.delayWithSeconds(1, completion: {
                                self.addVideo(innoId: innoId, videoKey:videoId, shortDesc: title, tagIds: videoTags)
                            })
                        }

                        callback(true)
                    }

                    upload.uploadProgress(closure: { (progress) in
                        self.progressView.progress = Float(progress.fractionCompleted)
                        self.progressLabel.text = "\(( Int(progress.fractionCompleted * 100)))%"
                    })

                    break
                case .failure(_):
                    callback(false)
                    break
                }
            })
        }

        catch {

        }
    }

在这种情况下,窗口会打开。但它没有打开网站。但是,如果我删除

,它可以正常工作
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("user-data-
dir=/Users/prajwal/Library/Application Support/Google/Chrome")
capability = DesiredCapabilities.CHROME
capability["pageLoadStrategy"] = "normal"
driver = webdriver.Chrome(desired_capabilities=capability, 
chrome_options=chromeOptions)
driver.get("https://www.google.com")

我哪里错了?

0 个答案:

没有答案