我正在制作一个android应用程序,它将登录到我的大学网站,然后单击页面上的出勤按钮,抓取数据,进行一些计算并向用户显示,但我无法从这里找到任何方法。我为此使用selendroid。问题出在驱动程序变量上。在Java应用程序中,我可以使用ChromeDriver,但对于Android使用什么?
package com.example.jtx.gneattendance;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.List;
import io.selendroid.SelendroidCapabilities;
import io.selendroid.SelendroidDriver;
import io.selendroid.standalone.SelendroidLauncher;
public class MainActivity extends AppCompatActivity {
int count = 0;
String arr[] = new String[15];
String atten = "";
TextView text;
public void cnt() throws Exception
{
WebDriver driver =null;
driver.get("https://academics.gndec.ac.in");
driver.findElement(By.id("username")).sendKeys("xxxxxxxxx");
driver.findElement(By.id("password")).sendKeys("xxxxxxxxx");
driver.findElement(By.name("submit")).click();
driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div/div[2]/form/button")).click();
List<WebElement> rows = driver.findElements(By.xpath("/html/body/form/table/tbody/tr"));
String p[] = new String[rows.size() + 1];
int pheld[] = new int[rows.size() + 1];
int pattende[] = new int[rows.size() + 1];
Double ppercent[] = new Double[rows.size() + 1];
for (int i = 1; i <= rows.size(); i++) {
p[i] = driver.findElement(By.xpath("/html/body/form/table/tbody/tr[" + i + "]/td[2]")).getText();
pheld[i] = Integer.parseInt(driver.findElement(By.xpath("/html/body/form/table/tbody/tr[" + i + "]/td[4]")).getText());
pattende[i] = Integer.parseInt(driver.findElement(By.xpath("/html/body/form/table/tbody/tr[" + i + "]/td[5]")).getText());
ppercent[i] = Double.valueOf((driver.findElement(By.xpath("/html/body/form/table/tbody/tr[" + i + "]/td[6]")).getText()));
if (ppercent[i] < 75.0) {
lecreq(pattende[i], pheld[i]);
}
arr[i] = " Subject name=" + p[i] + "<br> Lectures held=" + pheld[i] + " <br> Lectures Attended=" + pattende[i] + " <br> Percentage=" + ppercent[i] + " <br> Lectures needed=" + count + "<br><br><br>";
// System.out.println(arr[i]);
text = findViewById(R.id.textView1);
text.setText(arr[i]);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
cnt();
} catch (Exception e) {
e.printStackTrace();
}
}
public void lecreq(int m, int n) {
if ((m * 100 / n) < 75.0) {
m++;
n++;
count++;
lecreq(m, n);
}
}
}