gpt4 book ai didi

java - 元素不可见 : Element is not currently visible and may not be manipulated

转载 作者:太空宇宙 更新时间:2023-11-04 11:56:46 25 4
gpt4 key购买 nike

我正在尝试从下拉列表中选择一个元素。当我使用 getAttribute() 方法时,我已检索到 12 个元素:

    Select select = new Select(driver.findElement(By.xpath("//select[@id='dataset_downloadDataset_select']")));
List<WebElement> options = select.getOptions();
System.out.println(options.size());
for (int i=1; i<=11; i++){
System.out.println(options.get(i).getAttribute("value"));

检索 dropdowm 的 12 个元素后,我想选择其中一个。为此,我尝试了 Actions/Javascriptexecutor 但出现元素不可见异常。Action 方法使用的代码是:

    WebElement mnuElement;
WebElement submnuElement;

mnuElement = driver.findElement(By.xpath("//input[starts-with(@data-activates,'sele')][@value='XXXXXXXXXXX']"));
submnuElement = driver.findElement(By.xpath("//*[@id='dataset_downloadDataset_select']/option[4]"));
Actions builder = new Actions(driver);
builder.moveToElement(mnuElement).perform();
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id='dataset_downloadDataset_select']/option[4]")).click();

谁能帮我解决这个问题。

最佳答案

这取决于您使用的浏览器。 Chrome 可以点击选项而不扩展,而 Firefox 则无法处理。使用 select 进行选择。您使用的选项需要单击列表然后进行选择,但这样做更简单

Firefox(可能还有每个浏览器)的代码

WebDriver driver;//then choosing browser
element=driver.findElement(By.xpath("//select[@id='dataset_downloadDataset_select']"));//or whatever
Select select=new Select(element);

//To select what you want, this is selecting, nothing more

select.selectByValue("Mainframe File 1");//or other

关于java - 元素不可见 : Element is not currently visible and may not be manipulated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41315640/

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