【问题标题】:Selenium WD Unable to locate webelement in a popup window on cheaptickets.inSelenium WD 无法在cheaptickets.in 的弹出窗口中找到 webelement
【发布时间】:2018-09-02 18:47:09
【问题描述】:

在 URL "https://cheapticket.in/b2c/flights" 上,单击“注册”按钮后会出现一个弹出框,我想在其中输入电子邮件和所有其他字段,但抛出以下异常:

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: 
Element <input id="" class="fluid" name="login" type="text"> could not be
scrolled into view
package TestPackage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.GeckoDriverService;

public class CheapTickets {

    public static void main(String[] args){

        System.setProperty("driver.chrome.driver", "D:\\Selenium\\chromedriver.exe");
        WebDriver driver=new ChromeDriver();

        driver.get("https://cheapticket.in/b2c/flights");
        System.out.println("Loaded cheaptickets");

        //go to sign up
        driver.findElement(By.xpath("//a[@id='signup']")).click();
        System.out.println("Travelled to signup");
        driver.findElement(By.xpath("//input[@class='fluid']")).sendKeys("abc@abc.com");
    }
}

我该如何解决这个问题?

【问题讨论】:

  • 请发布您目前拥有的代码。
  • @ggorlen 我已经在问题中添加了到目前为止完成的代码。

标签: java selenium selenium-webdriver xpath


【解决方案1】:

@SuperShazam 看起来这个定位器在 DOM 中找到了 13 个元素,这可能是 Selenium 引发异常的原因。尝试为每个元素使用更具体的定位器。如果您无法创建更具体的定位器,请尝试迭代元素并检查所需的定位器是否可见。

【讨论】:

    【解决方案2】:

    我同意@baadnews,您在代码中用于获取电子邮件输入字段的 xpath 将匹配 DOM 中的 13 个元素。因此,您的代码将获得 DOM 中的第一个匹配项,该匹配项在页面上不可见,并且您会收到异常。

    你可以像这样使用更具体的 xpath

    email = driver.findElement(By.xpath("//div[@class='content']//input[@name='email']"))
    mobile = driver.findElement(By.xpath("//div[@class='content']//input[@name='mobile']"))
    name = driver.findElement(By.xpath("//div[@class='content']//input[@name='name']"))
    

    【讨论】:

      猜你喜欢
      • 2018-06-04
      • 2017-06-04
      • 2022-01-08
      • 1970-01-01
      • 2021-02-09
      • 2019-01-29
      • 2022-01-04
      • 1970-01-01
      • 2017-01-30
      相关资源
      最近更新 更多