用户界面仅包含一个 go 按钮,并且是go.xaml中的代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
BackgroundColor="Indigo"
Padding="10,20,0,0"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ExerciseApp.Login">
<StackLayout VerticalOptions="Center" Spacing="20">
<Button Text="Go" Clicked="Entry_Completed"/>
</StackLayout>
</ContentPage>
单击Go按钮后,facebook网页将会打开并自动填写用户名和密码并自动登录,以下代码存储在go.xaml.cs中:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plugin.AutoLogin;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace ExerciseApp
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Login : ContentPage
{
void Entry_Completed(object sender, EventArgs e)
{
Device.OpenUri(new Uri("http://www.facebook.com"));
Device.FindElement(By.Id("email")).SendKeys("john@hotmail.com");
Device.FindElement(By.Id("pass")).SendKeys("passjohn");
Device.FindElement(By.Id("u_0_3")).SendKeys(Key.click);
}
public Login()
{
InitializeComponent();
}
}
}
代码无法运行。任何人都可以与我分享一些想法吗?