在下面提到的案例中发现网络元素的问题
在网页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 Minute”(10分钟)选项字段,我们试图编写自己的xpath,但无济于事。
答案 0 :(得分:2)
请尝试以下行:
driver.findElement(By.xpath("//span[starts-with(@id,'select2-paste_expire_date')]")).click();
driver.findElement(By.xpath("//li[text()='10 Minutes']")).click();
对我有用。我已经在Chrome浏览器上检查过。