gpt4 book ai didi

javascript - Java代码通过 Selenium 打开Chrome URL但是无法点击按钮

转载 作者:行者123 更新时间:2023-11-30 06:22:18 24 4
gpt4 key购买 nike

下面是我编写的用于在 chrome 浏览器中打开 URL 并单击其上的按钮的代码。然而,尽管尝试通过 xpath、类和 CSS 选择器单击按钮,但它没有得到单击。任何建议代码有什么问题?P.S:我是这个社区和 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 > 按钮

X路径://*[@id="graphiql-container"]/div[1]/div[1]/div/div[2]/按钮

类:"button class="execute-button"title="执行查询(Ctrl-Enter)"

最佳答案

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

driver.get("URL");

关于javascript - Java代码通过 Selenium 打开Chrome URL但是无法点击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52439888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com