在使用selenium时,尽管切换了帧,java还是不能点击任何东西
我正试图提交一个关于Selenium WebDriver的应用程序
我输入了jobType和jobLocation,按下search,打开第一个结果,在new tab中,切换焦点,然后按下apply。现在,会出现一个弹出窗口,将页面上以前的1 iframe更改为2。我切换到第二个iframe,然后尝试向“name”的输入文本字段发送键,但不存在任何输入字段
driver.get("https://www.indeed.com");
WebElement what = driver.findElement(By.id("text-input-what"));
what.sendKeys("Java Programmer");
WebElement where = driver.findElement(By.id("text-input-where"));
Thread.sleep(500);
for (int i = 0; i < 20; i++) {
where.sendKeys(Keys.BACK_SPACE);
}
where.sendKeys("Toronto, ON");
WebElement submit = driver.findElement(By.xpath("//button[@class='icl-Button icl-Button--primary icl-Button--md icl-WhatWhere-button']"));
submit.click();
WebElement thirdElement = driver.findElement(By.xpath("/html[1]/body[1]/table[2]/tbody[1]/tr[1]/td[1]/table[1]/tbody[1]/tr[1]/td[2]/div[9]"));
thirdElement.click();
System.out.println(driver.getWindowHandle());
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
Thread.sleep(3000);
WebElement apply = driver.findElement(By.xpath("//button[@class='icl-Button icl-Button--branded icl-Button--md']//div[@class='jobsearch-IndeedApplyButton-contentWrapper'][contains(text(),'Apply Now')]"));
System.out.println(driver.findElements(By.tagName("iframe")).size());
apply.click();
driver.manage().window().maximize();
Thread.sleep(3000);
System.out.println(driver.getWindowHandle());
driver.switchTo().frame(1);
System.out.println(driver.getWindowHandle());
// Thread.sleep(3000);
System.out.println(driver.findElements(By.tagName("iframe")).size());
WebElement inputName = driver.findElement(By.xpath("//input[@id='input-applicant.name']"));
inputName.sendKeys("Adam Smith");
html code on ref page . Target indeed Page
预期结果是,我可以在文本字段中输入文本,而实际结果是,它会给出错误消息:
- 线程“main”组织中出现异常。openqa。硒。NoSuchElementException:没有这样的元素:无法定位元素:{“方法”:“xpath”,“选择器”:“//input[@id='input-applicator.name']” (会话信息:chrome=76.0.3809.87)
共 (0) 个答案