java - Selenium Webdriver 定位器(使用 java)
问题描述
我的按钮定位器不起作用。为此,我不能走得更远。我试过 xpath、cssSelector、ID。这些都不起作用。我上传代码。我是硒的新手。最后一个命令不起作用。
public class Upload {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","E:\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
driver.get("http://888.b7omc88t.io/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//code for boomcast portal login
driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[1]/input")).click();
driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[1]/input")).sendKeys("fatima@ssd-tech.com");
driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[2]/input")).click();
driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[2]/input")).sendKeys("1234");
driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[3]/button")).click();
driver.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/div/div[3]/div/ul/li[4]/a")).click();
driver.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/div/div[3]/div/ul/li[4]/ul/li/a")).click();
driver.findElement(By.xpath("//*[@id=\"smbscheduleobdStep2\"]")).click();
driver.findElement(By.xpath("/html/body/div[2]/div/div/div[3]/div/div/div[2]/div/form/div[1]/div[3]/div/div/div/input")).click();
driver.findElement(By.xpath("/html/body/div[2]/div/div/div[3]/div/div/div[2]/div/form/div[1]/div[3]/div/div/div/input")).sendKeys("01791719879");
driver.findElement(By.xpath("/html/body/div[2]/div/div/div[3]/div/div/div[2]/div/div[2]/a[3]")).click();
driver.findElement(By.cssSelector("#content > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > form:nth-child(3) > div:nth-child(5) > div:nth-child(3) > div:nth-child(2) > button:nth-child(1)")).click(); // This line is not getting executed
}
按钮的 HTML:
<div class="col-md-3 text-right">
<button id="smbscheduleobdStep3" type="button" class="btn btn-block">Saved files</button>
</div>
解决方案
根据您提供的用于单击按钮的 HTML,您必须诱导WebDriverWait按钮才能单击,您可以使用以下代码行:
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
// other code lines
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn-block' and @id='smbscheduleobdStep3' and contains(.,'Saved files')]"))).click();
推荐阅读
- ios - 在 App Store Connect 中提交应用以供审核时,iOS Build 不显示
- amazon-web-services - 如何设置 S3SinkConnector(找不到类)
- android - 更改 ZXing 中的扫描区域布局
- apache-spark - Spark结构化流式maxOffsetsPerTrigger似乎不起作用
- angular - 网络驱动程序上的节点模块
- docker - 如何在 Jenkinsfile 运行时为 dockerfile 设置环境变量?
- python - 如何通过矩阵numpy对循环进行矢量化
- c# - 无法在 UWP Toolkit 中设置 DataGridColumnHeader 的背景填充
- java - 输入不会一直传递给孩子
- spring - Spring 与 SFTP 的集成