我无法导航到存储在变量

时间:2015-08-28 12:58:05

标签: c# selenium-webdriver

string file = "c:\file.txt";

Process.Start(@"c:\script\call\other.exe");
Sleep();
Process.Start(@"c:\script\call\disconnect.exe");

string url = File.ReadAllText(file);

driver.Navigate().GoToUrl(url);

这就是我想要做的。第一个脚本(AutoIT)与桌面应用程序交互,导致Firefox窗口启动。我无法使用驱动程序与现有的浏览器会话进行交互,因此第二个脚本是从该窗口复制URL并粘贴到.txt文件。尝试读取文件Illegal characters in path时,程序仍然失败。我做了一些研究,似乎它与编码有关。有没有人有任何想法?

2 个答案:

答案 0 :(得分:0)

嗯,从我所看到的drivers将被声明为:

IWebDriver driver = new FirefoxDriver();  

(或其他浏览器驱动程序)。

此外,我知道在FirefoxDriver()您必须在网址的开头加入http://。也许你的问题很相似。

要使其适用于文件路径,您可以执行以下操作:

FirefoxBinary binary = new FirefoxBinary(@'c:\file.txt');
IWebDriver driver = new FirefoxDriver(binary);

答案 1 :(得分:0)

在文本文件的路径前添加@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); callbackManager = CallbackManager.Factory.create(); } @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_main, container, false); LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button); loginButton.setReadPermissions(Arrays.asList("public_profile", "user_friends")); // If using in a fragment loginButton.setFragment(this); // Other app specific specialization // Callback registration loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { accessTokenTracker = new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) { // Set the access token using // currentAccessToken when it's loaded or set. Profile.fetchProfileForCurrentAccessToken(); AccessToken.setCurrentAccessToken(currentAccessToken); } }; accessTokenTracker.startTracking(); profileTracker = new ProfileTracker() { @Override protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) { // App code if(currentProfile!=null) { Profile.setCurrentProfile(currentProfile); profile = currentProfile; } } }; profileTracker.startTracking(); // App code //token you have been granted to access the facebook sever AccessToken accessToken = loginResult.getAccessToken(); //user's profile thats login profile = Profile.getCurrentProfile(); final Bundle extras = new Bundle(); //error is HERE PROFILE IS NULL extras.putString(EXTRA_PROFILENAME, profile.getFirstName()); extras.putString(EXTRA_PROFILEID, profile.getId()); .... rest code } } @Override public void onDestroy() { super.onDestroy(); // accessTokenTracker.stopTracking(); profileTracker.stopTracking(); } public void onStop(){ super.onStop(); accessTokenTracker.stopTracking(); profileTracker.stopTracking(); } ,因为它未正确转义。

@

这应该允许你阅读文件。