我正在尝试创建一个可以在html中单击文本/按钮的类。页面有用户和密码,所以我使用JSOUP解析文档,使用.data插入用户和密码:
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中有了一个按钮,如下所示:
<a type="button" id="request" onclick="request(this)" class="lightButton"><i class="loading" style="display:none"><span class="ifont"></span></i>Request</a>
但是我不知道如何点击那个文本/按钮。
有人知道我怎么做的吗?谢谢
发布于 2018-09-25 04:43:56
这对我很有效
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();
}
}
https://stackoverflow.com/questions/52486681
复制相似问题