为了账号安全,请及时绑定邮箱和手机立即绑定

Selenium WD 无法在cheaptickets.in 的弹出窗口中找到webelement

Selenium WD 无法在cheaptickets.in 的弹出窗口中找到webelement

慕盖茨4494581 2021-08-25 18:08:55
在 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 bescrolled into viewpackage 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");    }}我该如何解决这个问题?
查看完整描述

2 回答

?
手掌心

TA贡献1942条经验 获得超3个赞

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


查看完整回答
反对 回复 2021-08-25
?
qq_遁去的一_1

TA贡献1725条经验 获得超7个赞

您在代码中用于获取电子邮件输入字段的 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']"))


查看完整回答
反对 回复 2021-08-25
  • 2 回答
  • 0 关注
  • 137 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信