Opening a link in a new tab is working for Firefox but not working for Chrome browser using Selenium -


i have test need open link in new tab. must work in firefox , chrome. first tried gmail link on google page.

on firefox works perfectly, gmail opened in new tab. on chrome gmail page opened in same window , menu remains open after right click. has come across problem?

beneath sample code.

firefox code:

firefoxprofile myprofile; profilesini profile = new profilesini();             myprofile = profile.getprofile("seleniumauto");              webdriver driver = new firefoxdriver(myprofile); driver.get("http://www.google.com");     driver.manage().window().maximize();  actions = new actions(driver); webelement e = driver.findelement(by.xpath("/html/body/div/div[3]/div[1]/div/div/div/div[1]/div[2]/a")); a.movetoelement(e); a.contextclick(e).sendkeys(keys.arrow_down)  .sendkeys(keys.enter).build().perform();             

chrome code:

chromeoptions options = new chromeoptions(); options.addarguments("--test-type"); webdriver driver = new chromedriver(options); driver.get("http://www.google.com");     driver.manage().window().maximize();*/      actions = new actions(driver); webelement e = driver.findelement(by.xpath("/html/body/div/div[3]/div[1]/div/div/div/div[1]/div[2]/a")); a.movetoelement(e); a.contextclick(e).sendkeys(keys.arrow_down)  .sendkeys(keys.enter).build().perform(); 

i've encountered same issue. apparently, arrow_down won't work, tried using keys combination , works me. code follows:

1) opening in new tab focus still on current tab

wait.until(expectedconditions.visibilityofelementlocated(by.xpath(your_path))); actions.keydown(keys.control).perform(); driver.findelement(by.xpath(your_path)).click(); actions.keyup(keys.control); 

2) opening in new tab , moving new tab

wait.until(expectedconditions.visibilityofelementlocated(by.xpath(your_path))); actions.keydown(keys.control).perform(); actions.keydown(keys.shift).perform(); driver.findelement(by.xpath(your_path)).click(); actions.keyup(keys.shift); actions.keyup(keys.control); 

hope helps.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -