hyperlink - How to verify whether a link read from file is present on webpage or not? -


i new @ automation. have write code follow

i have read around 10 url's file , store 1 hashtable need read 1 one url's hashtable , while iterating through url need read 1 more file conataining 3 url's , search them on webpage . if present need click link

i have written following code not getting logic checking whether link file present on webpage or not... please check code , me solve/improve it.

main test script  package com.samaritan.automation;  import java.util.hashtable; import java.util.set;  import org.junit.test; import org.openqa.selenium.webdriver; import org.openqa.selenium.firefox.firefoxdriver;  public class firstscript {      webdriver driver = new firefoxdriver();          string data;     commoncontrollers commoncontroll = null;     hashtable<string, string> recruiters = null;       @test     public void script() throws exception {           commoncontrollers commoncontroll = new commoncontrollers();         recruiters = new hashtable<string,string>();          recruiters = commoncontroll.readdatafromfile("d:/erecruiters/_recruiters.properties");          set<string> keys = recruiters.keyset();          for(string key: keys){          /**here need write function verify whether link read second file present on webpage or not**/         }    }      } 

and function read file hashtable

public hashtable<string, string> readdatafromfile(string filename) {             try {                 filereader fr = new filereader(filename);                 bufferedreader br = new bufferedreader(fr);                 string strline = null;                 string []prop = null;                 while((strline = br.readline()) != null) {                     prop = strline.split("\t");                     recruiters.put(prop[0], prop[1]);                 }                 br.close();                 fr.close();              }catch(exception exception) {                 system.out.println("unable read data recruiter file: " + exception.getmessage());             }             return recruiters;         } 

please take look! thanks

priya...you can use

 if(iselementpresent(by.linktext(linktextfoundfromfile))){       //code when link text present there  }else {       //code not finding link  } 

now following method generalized by object can use by.xpath, by.id etc.

 private boolean iselementpresent(by by) {      try {        driver.findelement(by);        return true;      } catch (nosuchelementexception e) {        return false;      }    } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -