元素不可交互异常:元素在Selenium Java中不可交互

ryoqjall  于 2022-12-29  发布在  Java
关注(0)|答案(1)|浏览(166)
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class E2E {

    public static void main(String[] args) throws InterruptedException {
    System.setProperty("webdriver.chrome.driver",  "D:\\Selenium\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.flygofirst.com/");

    driver.findElement(By.xpath("//span[@id='onewaymodal-id']")).click();
    Thread.sleep(25000);
    driver.findElement(By.xpath("//div[@id = 'oneWaybd']//div[@class ='fromTo']/div[1]")).sendKeys("Ch");

    

    
    

    

    }

}

我试图在“发件人”文本框中发送密钥,我正在获取的元素不是难以处理的。
我提供了等待时间,以便所有的网页元素将加载。之后,我也得到了相同的异常元素不难处理。
有人能帮我一下吗

cgfeq70w

cgfeq70w1#

你必须修改定位器,试试这个,它的工作:

// to handle the Accept Cookies button
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#cookie-btn"))).click();
        
driver.findElement(By.xpath("//span[@id='onewaymodal-id']")).click();
Thread.sleep(1000);

// modified the below locator
driver.findElement(By.xpath("(.//div[@class='fromTo']//input[@id='roundTripbdFromView'])[2]")).sendKeys("ch");

我也回答了你之前的问题,检查一下,如果有效,就把它标记为答案。

相关问题