【问题标题】:in Selenium java, sendkeys function is not entering the data but locating the exact location在 Selenium java 中,sendkeys 函数不是输入数据而是定位确切位置
【发布时间】:2022-01-30 11:08:12
【问题描述】:

在 Selenium java 中,sendkeys 函数不是输入数据而是定位确切位置。 网址:https://www.makemytrip.com/

    driver.findElement(By.cssSelector(".langCard.fixedCard.bounceAni>span")).click();
    WebElement from = driver.findElement(By.cssSelector("#fromCity"));
    
    from.sendKeys("ben");

【问题讨论】:

    标签: java selenium selenium-webdriver


    【解决方案1】:

    要在此处插入搜索词,您需要先单击表单元素,然后将搜索词插入到搜索输入中。
    像这样的:

    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".langCard.fixedCard.bounceAni>span"))).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#fromCity"))).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[@for='fromCity']//input"))).sendKeys("ben");
    
    

    【讨论】:

    • ,出现此错误:线程“主”org.openqa.selenium.ElementClickInterceptedException 中的异常:元素单击被拦截:元素 在点 (245, 255) 不可点击。其他元素会收到点击:
    • 嗯,我明白了。尝试在最后一行代码之前添加一些 1 秒的虚拟延迟
    【解决方案2】:

    您是否在无头模式下运行此程序?如果不是,您可以将上面代码 sn-p 中的 ExpectedConditions 更改为

    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".langCard.fixedCard.bounceAni>span"))).click();
    wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#fromCity"))).click();
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@for='fromCity']//input"))).sendKeys("ben");
    

    【讨论】:

      猜你喜欢
      • 2014-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      • 2021-12-28
      相关资源
      最近更新 更多