Java Code正在通过Selenium打开Chrome URL,但无法单击按钮



下面是我编写的代码,用于在chrome浏览器中打开URL,然后单击其上的按钮。然而,尽管尝试通过 xpath、类和 CSS 选择器单击按钮,但它没有得到点击。任何建议代码有什么问题? PS:我是这个社区和Java的新手。

public void testUntitledTestCase() throws Exception 
{
for (int i = 1; i < 364 ; i++) 
{
driver.get("URL+i+");  
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='Docs'])[1]/following::div[12]")).click();
driver.findElement(By.xpath("//button[@value='graphiql-container']")).click();
driver.findElement(By.className("execute-button")).click();
driver.findElement(By.xpath("//button[contains(@class='execute-button')]")).click();
driver.findElement(By.xpath("//button[@class='execute-button']")).click();
}
}

下面是一个 HTML 部分: CSS 选择器:

graphiql-container>div.editorWrap>div.topBarWrap>div>div.execute-button-wrap> button

Xpath: *[@id="graphiql-container"]/div[1]/div[1]/div/div[2]/button

类: "button class="execute-button" title="Execute Query (Ctrl-Enter(">

您可以尝试直接打开 URL 而不放入 for 循环吗?提供完整的 URL 并检查您是否能够单击该按钮。

driver.get("URL"(;

几个月前,我在一个项目中使用Selenium(Java(,有一些问题需要处理 - 特别是在测试基于ajax的网站时。我最终使用了Arquillian Graphene-一堆Selenium扩展,它们增加了功能并且已经处理了其中一些问题。你绝对应该看看它:

http://arquillian.org/arquillian-graphene/

除此之外,我可以分享一些在那些日子里有帮助的书签:

http://www.testautomationguru.com/selenium-webdriver-how-to-wait-for-expected-conditions-using-awaitility/http://www.naveenautomationlabs.com/2018/04/mystery-of-staleelementreferenceexcepti.html

最新更新