Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JAVA自动填充网页中的用户名和密码字段_Java_Mysql_Url_Gmail - Fatal编程技术网

使用JAVA自动填充网页中的用户名和密码字段

使用JAVA自动填充网页中的用户名和密码字段,java,mysql,url,gmail,Java,Mysql,Url,Gmail,这就是我要做的,我需要java自动打开一个像mail.google.com这样的网页,点击一个按钮,将用户名和密码输入到相应的框中。现在我知道了打开浏览器并将其指向提供的特定url的代码,我只是想知道是否有方法告诉java在相应的框中填写用户名和密码。顺便说一下,我已经完成了使用JAVA将MYSQL数据库中的数据转换成字符串变量的工作……有什么帮助或建议吗???使用Selenium。这是一个很好的库,您可以在其中操纵网页操作。 i、 isElementPresent(“元素的xpath来了”);

这就是我要做的,我需要java自动打开一个像mail.google.com这样的网页,点击一个按钮,将用户名和密码输入到相应的框中。现在我知道了打开浏览器并将其指向提供的特定url的代码,我只是想知道是否有方法告诉java在相应的框中填写用户名和密码。顺便说一下,我已经完成了使用JAVA将MYSQL数据库中的数据转换成字符串变量的工作……有什么帮助或建议吗???

使用Selenium。这是一个很好的库,您可以在其中操纵网页操作。 i、 isElementPresent(“元素的xpath来了”);将检查元素是否已加载,如果已加载,则可以使用selenium.type(“xpath”,String/integer)在该字段中键入。然后按selenium。单击(“元素”);您可以单击一个元素,例如submit按钮或其他东西

例如,这(不检查当前元素)应该打开Google.com并搜索“键入一些随机文本”:

package com.example.tests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.regex.Pattern;

public class Googletest {
    private Selenium selenium;

    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://www.google.com/");
        selenium.start();
    }

    @Test
    public void testGoogletest() throws Exception {
        selenium.open("/");
        selenium.type("//div[@id='gs_lc0']/input", "type some random text");
        selenium.click("//div[@id='gbqfbw']/button");
    }

    @After
    public void tearDown() throws Exception {
        selenium.stop();
    }
}