java - Open Google links into new tab -


i want open google search results new tab. tried code:

webdriver driver = new chromedriver();         driver.get("http://www.google.com/xhtml");         thread.sleep(5000);         webelement searchbox = driver.findelement(by.name("q"));         searchbox.sendkeys("chromedriver");         searchbox.submit();          system.out.println("current url: " + driver.getcurrenturl());          webdriverwait wait = new webdriverwait(driver, 10);         wait.until(expectedconditions.presenceofelementlocated(by.cssselector("h3.r a")));          list<webelement> results = driver.findelements(by.xpath("//h3[@class='r']/a"));          (int = 0; < results.size(); i++)         {             string selectlinkopeninnewtab = keys.chord(keys.control,keys.return);             driver.findelement(by.xpath("//h3[@class='r']/a")).sendkeys(selectlinkopeninnewtab);              system.out.println("google result " + results.get(i).gettext());         } 

so far code opens empty tabs , prints name of search results. how can open links searh results?

just change below line inside loop :-

driver.findelement(by.xpath("//h3[@class='r']/a")).sendkeys(selectlinkopeninnew‌​tab); 

to

results.get(i).sendkeys(selectlinkopeninnewtab); 

it's working...:)


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -