我是第一次打开一个页面,但是在成功加载页面时,注册表格马上就来了。我想在打开的页面上工作,但如果不处理页面加载上立即出现的注册表格,这是不可能的,但问题是我无法将我的控制切换到正在打开的登记表上。我使用Selenium WebDriver和Java作为脚本语言。
因为这个问题是与我的一些官方项目,所以我不能分享确切的网址,但我已经设法找到另一个网址,也行动类似的URL,我面临的问题。以下是我提供的替代网址:
jquery/index.php
在上面的URL中,我想要在加载的页面中工作,但是在处理注册表单之前无法这样做。请告诉我如何使用Selenium WebDriver和Java语言将控件切换到注册表单。
发布于 2018-06-20 17:05:40
您必须使用上面的链接搜索concept.The查找元素,注册弹出窗口是,在iframe中没有可用的。因此,首先您必须找到注册表单的父WebElement,然后可以使用父元素引用访问所需的元素。
//Finding the Parent Element of the Registration Form
WebElement popUp=driver.findElement(By.className("fancybox-skin"));
//Finding the Name Input Text Field using the Parent Element
popUp.findElement(By.xpath(".//*[@id='load_form']/fieldset[1]/input")).sendKeys("Subburaj");类似地,您可以使用弹出元素(父元素)访问所有适用的注册表单元素。
注意:我已经测试了上面的代码,它运行良好。
编辑:完整代码:
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.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Way2Automation {
public static void main(String args[]){
System.setProperty("webdriver.chrome.driver", "drivers/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://way2automation.com/way2auto_jquery/index.php");
//Explicit wait is added after the Page load
WebDriverWait wait=new WebDriverWait(driver,20);
wait.until(ExpectedConditions.titleContains("Welcome"));
WebElement popUp=driver.findElement(By.className("fancybox-skin"));
popUp.findElement(By.xpath(".//*[@id='load_form']/fieldset[1]/input")).sendKeys("Subburaj");
popUp.findElement(By.xpath(".//*[@id='load_form']/fieldset[2]/input")).sendKeys("987654321");
}
}https://stackoverflow.com/questions/50953284
复制相似问题