首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >单击html a text with JAVA

单击html a text with JAVA
EN

Stack Overflow用户
提问于 2018-09-25 04:12:55
回答 1查看 349关注 0票数 0

我正在尝试创建一个可以在html中单击文本/按钮的类。页面有用户和密码,所以我使用JSOUP解析文档,使用.data插入用户和密码:

代码语言:javascript
复制
Document document = Jsoup.connect("url").data("user", user)
                .data("password", password)
                .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0")
                .timeout(3000).post();

在这一点上,一切工作正常。但现在我在html中有了一个按钮,如下所示:

代码语言:javascript
复制
<a type="button" id="request" onclick="request(this)" class="lightButton"><i class="loading" style="display:none"><span class="ifont"></span></i>Request</a> 

但是我不知道如何点击那个文本/按钮。

有人知道我怎么做的吗?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-25 04:43:56

这对我很有效

代码语言:javascript
复制
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class TestMain {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "C:\\tests\\chromedriver.exe");

        ChromeOptions options = new ChromeOptions();
        options.addArguments("window-size=1024,768");

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        WebDriver driver = new ChromeDriver(capabilities);

        driver.get("http://google.com/");

        if (driver instanceof JavascriptExecutor) {
            ((JavascriptExecutor) driver).executeScript("document.getElementsByClassName(\"gb_we\")[0].click()");
        }

    WebElement fName=driver.findElement(By.id("identifierId"));
    fName.sendKeys("test@gmail.com");

    WebElement btnNext =driver.findElement(By.id("identifierNext"));
    btnNext.click();

    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52486681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档