-3

Screenshot of the element I want to click:

I automating my website(new to automation). once i login i get to another page where selenium web driver is not able to find any of the elements(I tried all possibilities even sso related).

Only solution i could find was using tabs and enter.

So when i enter that page i need to click 9 time "TAB" key from the keyboard and then enter so that my login is verified. since i don't have any element using which i can perform the tab and enter actions. is there a way where once i get to that page the web driver starts pressing "TAB" key 9 times and then "Enter" on 10 time.

Please help I have been working on this over a week now and not getting anywhere.

optimist_creeper-main class:

package Modules;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import Modules.HomePage;

public class MainClass {
    String appUrl = "als-stg-1.mtvn.ad.viacom.com/webqa/";

    @Test public void MainTest() {
        System.setProperty("webdriver.gecko.driver", "C:\\Shayni Coding\\Automation\\Gecko\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get(appUrl);
        HomePage home = new HomePage();
        home.HomePageTest(driver);
    }
}

Home Page class:

public class HomePage {
    @BeforeClass public void beforeClass() {
        System.out.println("before class");
    }
    public void HomePageTest(WebDriver driver) {
        driver.manage().window().maximize();
        WebElement email = driver.findElement(By.id("cred_userid_inputtext"));
        email.sendKeys("shayni@outlook.com");
        WebElement pass = driiver.findElement(By.id("cred_password_inputtext"));
        pass.sendKeys(Keys.ENTER);
        pass.click();
        String expectedTitle = "VMS Web";
        String actualTitle = driver.getTitle();
        Assert.assertEquals(expectedTitle,actualTitle);
    }
}

Thanks.

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
Shayni Sood
  • 17
  • 1
  • 6
  • Your question is not that much clear. "once i login i get to another page where selenium web driver is not able to find any of the elements" - what does that mean? Clarify your intention. – optimistic_creeper Oct 02 '16 at 20:32
  • You've asked a question but have posted none of the code you have written nor have you posted the relevant HTML or a link to the page. I'm not sure how we're supposed to help you. – JeffC Oct 02 '16 at 20:40

1 Answers1

0

Just get a random object like the body tag and use that to send your key presses.

e.g.

 WebElement dummyElement = driver.findElement(By.xpath("/html/body"));
 for (int i = 0; i < 9; ++i) {
     dummyElement.sendKeys(keys.TAB);
 }
 dummyElement.sendKeys(keys.ENTER);

The above code finds the body take and sets it as an element. It then presses the tab key 9 times and then presses the enter key. Which is what you asked for. Hope that helps.

Moser
  • 287
  • 2
  • 12