我正在尝试自动化页面[链接] https://qlb21.resources.hewitt.com/cl77ybr5qc/ybr5cl772b/CsLogn010InptOpen.do?fTkn=539f4eddc99aef9eb1c8da11d13a3654&fWdw=intro&eWlmYBR5ClntId=00398&wdw=primary&fPg=%2FCsLogn005WelcOpen。 点击上面的链接,你会得到一个提示。现在我能够处理,但是点击iframe上的继续按钮后,主页显示用户ID和密码,我尝试使用sendkeys发送但是徒劳无功
`
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import com.selenium.commons.Configuration;
public class Home {
public WebDriver driver = Configuration.driver;
@FindBy(id="usrId")
private WebElement user;
@FindBy(id="pswd")
private WebElement pswd;
@FindBy(id="tranId'")
private WebElement tranId;
@FindBy(id="logOn")
private WebElement logOn;
public Home()
{
PageFactory.initElements(Configuration.driver, this);
}
public void logon(String Username,String Password,String trns)
{
Configuration.driver.get(Configuration.URL);
Configuration.driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
try{
Thread.sleep(10000);
}
catch(Exception e)
{
}
Configuration.driver.switchTo().frame(Configuration.driver.findElement(By.xpath("//iframe[@id='lightbox_iframe_cookieBanner']")));
Configuration.driver.findElement(By.xpath("//a[text()='Continue']")).click();
driver.manage().window().maximize();
System.out.println(driver.getTitle());
driver.findElement(By.id("usrId")).sendKeys("Babita Sethi");
}
`
答案 0 :(得分:3)
在进行用户名字段查找之前,您应该从iframe
切换回来,执行以下操作:
driver.switchTo().defaultContent();
答案 1 :(得分:0)
该提示位于iframe中。但主页不在iframe中。每当您想要在主页上执行操作时,您应该切换回默认内容。即driver.switchTo()。defaultContent();