简体   繁体   English

Selenium WebDriver Java-首次打开页面时会出现注册表格

[英]Selenium WebDriver Java - Registration form coming on opening a page for first time

I am opening a page for the first time but on successful loading of the page a Registration form is immediately coming. 我是第一次打开页面,但是成功加载页面后会立即出现注册表格。 I want to work on the page that gets opened but that is not possible without handling the registration form that is immediately coming on the page load but the problem is that I am unable to switch my control to that Registration form that is opening. 我想在打开的页面上工作,但是如果不处理立即在页面加载中出现的注册表格,那是不可能的,但是问题是我无法将控件切换到正在打开的注册表格。 I am using Selenium WebDriver along with Java as the scripting language. 我将Selenium WebDriver和Java用作脚本语言。

Since this problem is with some official project of mine so I am unable to share the exact URL but I have managed to find another URL that also acts similar to the URL that I am facing problem with. 由于此问题与我的某个官方项目有关,因此我无法共享确切的URL,但我设法找到了另一个URL,该URL的行为也与我面临的URL类似。 I am providing that substitute URL below: 我在下面提供该替代URL:

http://way2automation.com/way2auto_jquery/index.php http://way2automation.com/way2auto_jquery/index.php

In the above URL, I want to work in the page that gets loaded but am unable to do it before handling the registration form. 在上述网址中,我想在已加载的页面上工作,但在处理注册表之前无法执行此操作。 Please tell me how to switch control to the registration form using Selenium WebDriver and Java as the language. 请告诉我如何使用Selenium WebDriver和Java作为语言将控制权切换到注册表单。

You have to find the element using the chained search concept.The above Registration popup is not available within iframe. 您必须使用链式搜索概念来查找元素。以上注册弹出窗口在iframe中不可用 So, first you have to find the Parent WebElement of the Registration form and then you can access the required element using parent element reference. 因此,首先必须找到“注册”表单的“父级Web元素”,然后可以使用父级元素引用访问所需的元素。

    //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");

Similarly, you can access all the applicable registration form element using the popup element(parent element) 同样,您可以使用popup元素(父元素)访问所有适用的注册表单元素

Note: I have tested the above piece of code and it is working fine 注意:我已经测试了上面的代码,并且工作正常

Edit: Full Code: 编辑:完整代码:

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");

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在java中使用selenium webdriver从excel中为webform(如任何注册页面)赋予价值? - How to put value on webform (like any registration page) from excel using selenium webdriver in java? Selenium Webdriver不打开URL而是仅打开空白页 - Selenium webdriver not opening url instead opening a blank page only Selenium WebDriver首先设置了Java示例 - Selenium WebDriver first Java example to set up JAVA / Selenium-单击页面上的第一个按钮有50%的时间有效 - JAVA/Selenium - clicking the first button on the page works 50% of the time Selenium WebDriver Java识别表单输入按钮 - Selenium WebDriver Java identify form input button Selenium Webdriver(Java)-脚本之间的时间延迟 - Selenium Webdriver (Java) - time delay between the scripts Java与Selenium WebDriver一起使用上一页和元素 - Java with selenium webdriver to work with previous page and element 使用Java获取Selenium WebDriver的页面标题 - Get page title with Selenium WebDriver using Java Firefox Web浏览器50.1.0不能使用Selenium Webdriver 3.0.1和Java 1.8打开 - Firefox web browser 50.1.0 is not opening with Selenium webdriver 3.0.1 and Java 1.8 Selenium Webdriver Java代码,如果在设置的时间段后找不到页面上的文本,则显示消息 - Selenium Webdriver Java code to display message if text on page cannot be found after a set time period
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM