java - Selenium: Why .click() doesn't work in this case && how to check if a button is clicked? -


title edited: "selenium: how check if link opened in new tab?"

i need create junit test should check if click on button cause opening link in new tab. doing i've faced problem: looks .click() doesn't suppose to. here's fragment of html:

<div class="small-5 column store-btns">    <a class="google_play_btn" target="_blank" href="https://google.com">       <img class="img-responsive"src="/s/img/buy/google_play_btn_blue.svg" alt>    </a>    <a class="app_store_btn" target="_blank" href="https://apple.com/">       <img class="img-responsive"src="/s/img/buy/app_store_btn_blue.svg" alt>    </a> </div> 

edited: here's simple junit test:

@before public void setup(){     driver = new safaridriver();     pause = new webdriverwait(driver, 2000); }  @after public void teardown(){     driver.close();     driver.quit(); }  @test: public void testlink() throws interruptedexception{     driver.get("http://linktotestedpage");     webelement googleplaybutton = pause.until(expectedconditions.visibilityofelementlocated(by.classname("google_play_btn")));     googleplaybutton.click();     list<string> browsertabs = new arraylist<string>(driver.getwindowhandles());     driver.switchto().window(browsertabs.get(1));     string titlegp = driver.gettitle();      assert.asserttrue("failure: link ok", titlegp.equals("google")); 

i expect new safari tab opened after googleplaybutton.click();, driver quits. see

indexoutofboundsexception: index 1, size 1 

where wrong? thanks.

i add additional check since windowshandle explicitly unordered , there no guarantee last tab 1 index 1

string currenthandle = driver.getwindowhandle(); list<string> browsertabs = new arraylist<string>(driver.getwindowhandles());  (string handle: browsertabs){     if (handle != currenthandle){         driver.switchto().window(handle);         //perform addition action needed;         //when done close window         driver.close();         driver.switchto().window(currenthandle);     } } string titlegp = driver.gettitle(); 

note: untested code side


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -