![](/img/trans.png)
[英]How to put value on webform (like any registration page) from excel using selenium webdriver in java?
[英]Selenium WebDriver Java - Registration form coming on opening a page for first time
我是第一次打開頁面,但是成功加載頁面后會立即出現注冊表格。 我想在打開的頁面上工作,但是如果不處理立即在頁面加載中出現的注冊表格,那是不可能的,但是問題是我無法將控件切換到正在打開的注冊表格。 我將Selenium WebDriver和Java用作腳本語言。
由於此問題與我的某個官方項目有關,因此我無法共享確切的URL,但我設法找到了另一個URL,該URL的行為也與我面臨的URL類似。 我在下面提供該替代URL:
http://way2automation.com/way2auto_jquery/index.php
在上述網址中,我想在已加載的頁面上工作,但在處理注冊表之前無法執行此操作。 請告訴我如何使用Selenium WebDriver和Java作為語言將控制權切換到注冊表單。
您必須使用鏈式搜索概念來查找元素。以上注冊彈出窗口在iframe中不可用 。 因此,首先必須找到“注冊”表單的“父級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");
同樣,您可以使用popup元素(父元素)訪問所有適用的注冊表單元素
注意:我已經測試了上面的代碼,並且工作正常
編輯:完整代碼:
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.