C#Selenium使用代理与chrome的配置文件

时间:2018-03-28 14:56:12

标签: c# google-chrome selenium

我想用我的个人资料和代理打开chrome。这段代码正在改善我的IP:

options.AddArguments("user-data-dir=C:\\Users\\Kamil\\AppData\\Local\\Google\\Chrome\\User Data");

当我添加这一行时:

System.Threading.Thread.Sleep(2000);

程序开始忽略代理。我究竟做错了什么?另外我想问你们,我怎样才能更改这一行:

import UIKit
import AVFoundation


class TestViewController: UIViewController, AVSpeechSynthesizerDelegate {

let synthesizer = AVSpeechSynthesizer()


@IBOutlet weak var textViewOutlet: UITextView!


@IBAction func pauseSpeech(_ sender: Any) {
    synthesizer.pauseSpeaking(at: AVSpeechBoundary.word)
}

@IBAction func stopSpeech(_ sender: Any) {
    synthesizer.stopSpeaking(at: .word)
}

@IBAction func cancelButton(_ sender: Any) {
    synthesizer.continueSpeaking()
}

@IBAction func speak(_ sender: AnyObject) {
    let string = textViewOutlet.text!
    let utterance = AVSpeechUtterance(string: string)
        utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")
        synthesizer.speak(utterance)
}


override func viewDidLoad() {
    super.viewDidLoad()
        synthesizer.delegate = self
        textViewOutlet.font = .systemFont(ofSize: 20)
}

func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString characterRange: NSRange, utterance: AVSpeechUtterance) {
    let mutableAttributedString = NSMutableAttributedString(string: utterance.speechString)
        mutableAttributedString.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.blue, range:  NSMakeRange(0, (utterance.speechString as NSString).length))
        mutableAttributedString.addAttribute(.foregroundColor, value: UIColor.red, range: characterRange)
        textViewOutlet.attributedText = mutableAttributedString
        textViewOutlet.font = .systemFont(ofSize: 20)
}

func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {
    textViewOutlet.attributedText = NSAttributedString(string: utterance.speechString)
    textViewOutlet.font = .systemFont(ofSize: 20)
}

}

使程序暂停,但不要冻结它。谢谢你的帮助!

2 个答案:

答案 0 :(得分:0)

由于用户数据行,它可能对您造成错误。它应该如下所示:

options.AddArguments("--user-data-dir=C:\\Users\\Kamil\\AppData\\Local\\Google\\Chrome\\User Data");

答案 1 :(得分:0)

暂停的问题是暂停主线程,您必须创建另一个线程并将所有代码放在该线程上。

public static void DoWork()
{

//put all your code in here, and you then you can pause it without  it freezing

}

public static void StartWorker()
{
    Thread worker = new Thread(DoWork);
    worker.IsBackground = true;
    worker.SetApartmentState(System.Threading.ApartmentState.STA);
    worker.Start()
}