java - How to open url on another tab at same browser using selenium webdriver? -


i want open url on new tab clicking on button add account. working framework, i've found solution don't understand how apply it.

below code i've find element , return performing operations. can 1 let me know integrate code opening url in new tab, using code?

private boolean operatewebdriver(string operation, string locator,             string value, string objectname) throws exception {         boolean testcasestep = false;          try {             system.out.println("operation execution in progress");             webelement temp = getelement(locator, objectname);             if (operation.equalsignorecase("sendkey")) {                 temp.sendkeys(value);             }             thread.sleep(1000);             driver.manage().timeouts().implicitlywait(5, timeunit.seconds);             if (operation.equalsignorecase("click")) {                 temp.click();                  //try open account on tab.                 string mywindowhandel= driver.getwindowhandle();                 driver.switchto().window(mywindowhandel);              }             if (operation.equalsignorecase("verify")) {                 system.out.println("verify--->" + temp);                 temp.isdisplayed();              }             testcasestep = true;          } catch (exception e) {             system.out.println("exception occurred operatewebdriver"                     + e.getmessage());              // take screenshot if testcase not working.              system.out.println("taking screen shot");             file scrfile = ((takesscreenshot)driver).getscreenshotas(outputtype.file);             fileutils.copyfile(scrfile, new file("d:\\softs\\eclipse-jee-kepler-sr1-win32\\workspace\\automationframework\\screenshot\\screenshot.jpeg"));          }          return testcasestep;     }      public webelement getelement(string locator, string objectname)             throws exception {         webelement temp = null;         system.out.println("locator-->" + locator);         if (locator.equalsignorecase("id")) {             temp = driver.findelement(by.id(objectname));          } else if (locator.equalsignorecase("xpath")) {             temp = driver.findelement(by.xpath(objectname));             system.out.println("xpath temp ----->" + temp);         } else if (locator.equalsignorecase("name")) {             temp = driver.findelement(by.name(objectname));         }         return temp;      }  } 

you can add if condition operatewebdriver()

    if (operation.equalsignorecase("newtab")) {         system.out.println("newtab" + temp);         actions newtab = new actions(driver);         newtab.keydown(keys.command).click(temp).keyup(keys.command).build().perform();          // switch windows , other stuff plan here after opening new tab      } 

for example if landed on http://stackoverflow.com , want open questions button in new tab similar want do, can call method this:

        //operatewebdriver(string operation, string locator, string value, string objectname)         operatewebdriver("newtab", "xpath", "", "//*[@id='nav-questions']"); 

for more info on opening new tab using selenium:
how open new tab using selenium webdriver , start link?


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -