【问题标题】:How to SendKeys in Selenium for my Website如何在 Selenium 中为我的网站发送密钥
【发布时间】:2015-07-19 14:37:55
【问题描述】:

我正在尝试自动化页面 [Link]https://qlb21.resources.hewitt.com/cl77ybr5qc/ybr5cl772b/CsLogn010InptOpen.do?fTkn=539f4eddc99aef9eb1c8da11d13a3654&fWdw=intro&eWlmYBR5ClntId=00398&wdw=primary&fPg=%2FCsLogn005WelcOpen。 单击上面的链接后,您将收到一个提示。该提示现在我可以处理,但是在单击 iframe 上的继续按钮后,主页在该 UserId 文本框中显示用户 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");

}

`

【问题讨论】:

    标签: java selenium selenium-webdriver webdriver pageobjects


    【解决方案1】:

    您也应该从iframe 切换回来,在进行用户名字段查找之前,请执行以下操作:

    driver.switchTo().defaultContent();
    

    【讨论】:

    • 在stackoverflow中,我们不是说谢谢,而是赞成/接受。
    【解决方案2】:

    该提示在 iframe 中。但主页不在 iframe 中。每当您想在主页上执行操作时,您都应该切换回默认内容。即 driver.switchTo().defaultContent();

    【讨论】:

      猜你喜欢
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2019-10-13
      • 2021-04-21
      • 1970-01-01
      相关资源
      最近更新 更多