Web元素在下面提到的情况下发现问题

在网页https://pastebin.com/上,需要从“粘贴过期:”下拉列表中选择选项“ 10分钟”

以下是已采取的步骤:

//Identification the Never option and clicking it the dropdown to show up
//This part of the code works
WebElement pasteExpiration = driver.findElement(By.xpath("//*[@class='form_frame_left']//*[@title = 'Never']"));
pasteExpiration.click();

//Selecting the'10 Minute' option, this code is not identified by the WebDriver
WebElement pasteExpiration10Minutes = driver.findElement(By.cssSelector("#select2-paste_expire_date-q4-container"));


WebDriver没有看到“ 10分钟”选项字段,我们试图编写自己的xpath,但没有任何效果。

最佳答案

请尝试以下行:

driver.findElement(By.xpath("//span[starts-with(@id,'select2-paste_expire_date')]")).click();
driver.findElement(By.xpath("//li[text()='10 Minutes']")).click();


它为我工作。我已经检查了chrome浏览器。

09-30 14:28
查看更多