How to compare data in excel sheet with text in website

In my test case I have to fill up a form for a student admission.
There is a drop-down to select MALE and FEMALE.
For data to be inserted in the form, I am picking my data from excel sheet and writing them in website.
But when its come to select the Gender I am not able to select Male and Female according to the data in the excel sheet.

I have written and Male and Female (in different cells)in front of the  student names .
What I want to do is pick the Male or Female word from excel sheet, compare it with the gender provided in the drop-down and then move forward accordingly.

~~Screenshot of the Gender drop-down in my application

How to compare data in excel sheet with text in website

~~Screenshot of the excel sheet I am using

How to compare data in excel sheet with text in website

Is it possible to do?
If Yes, please suggest how should I proceed.

Train Asked on November 10, 2014 in Selenium WebDriver.
  • 3 Answer(s)

    HI Som

    Characters are cases sensitive and i can see case difference in your sheet and on Webpage
    you can try making value in uppercase in your sheet

    let me know if it works

    Regards
    Ankit

    Vice Professor Answered on November 10, 2014.

    Doctor Ankit is back ­čÖé

    on November 10, 2014.

    Hi Ankit

    The characters are not case-sensitive in the whole software.

    Let me tell you step by step what I want to do

    1. I want the code to pick the Male word from the excel sheet and store in a string S1
    2. Then code should pick the text (which is at the top of the drop-down value list) and save in a string S2
    3. Compare S1 and S2 .
    4. If S1 = S2 then click on drop-down value 1 (MALE) and proceed
    OR
    5. If S1 =! S2 then click on drop-down value 2 (FEMALE) and proceed

    on November 10, 2014.

    ┬áSame thing i am trying to say because of case sensitive s1=s2 is never true so it isnt executing that codetry changing value in excel sheet from Male to “MALE”

    on November 10, 2014.
    Add Comment

    Hi,

    Why dont use driver.sendkeys and send the data in the excel to that field . Give it a try it works for me.

    Train Answered on November 10, 2014.

    Hi mallik

    I tried that idea but the thing is the Gender fields is non- writeable so forcefully I have to select a value from the drop-down and proceed.

    on November 10, 2014.
    Add Comment

    Hi Som,

    Try this:

    // This is actually your written function to get the test data from excel, just for an example
    
    String sGender = ExcelUtils.getCellData(TestCaseRow, GenderColumn)
    
    drpdwn_Gender(sGender);
    //Page Object Model
    
    public void drpdwn_Gender(String sGender) throws Exception{
    
    element = null;
    
    try{
    
    Select element= new Select(driver.findElement(By.id("Gender")));
    
    Log.info("Gender dropdown on Student Form is found.");
    
    element.selectByVisibleText(sGender);
    
    }catch (Exception e){
    
    Log.error("Gender dropdown on Student Form is not found");
    
    throw(e);
    
    }
    
    }
    
    

    Regards,
    Lakshay Sharma

    Professor Answered on November 10, 2014.

    Hi Lakshay

    I think there is some miss-understanding with my question
    Let me tell you step by step what I want to do

    1. I want the code to pick the Male word from the excel sheet and store in a string S1
    2. Then code should pick the text (which is at the top of the drop-down value list) and save in a string S2
    3. Compare S1 and S2 .
    4. If S1 = S2 then click on drop-down value 1 (MALE) and proceed
    OR
    5. If S1 =! S2 then click on drop-down value 2 (FEMALE) and proceed

    on November 10, 2014.

    Actually your logic is not correct, by that you need to keep a static value of MALE either in your excel sheet or in your code. Still I am giving you a peice of code, you can work on that and make it work for it, Just for an idea purpose. Close this question as well.

    
    String sGender = ExcelUtils.getCellData(TestCaseRow, GenderColumn)
    
    Select element= new Select(driver.findElement(By.id("Gender")));
    
    String S1 = element.getOptions().get(1).getText();
    if(S1.equals(sGender)){
    
    drpdwn_Gender("MALE");
    
    }else{
    
    drpdwn_Gender("FEMALE");
    
    }
    
    }
    
    //Page Object Model
    
    public void drpdwn_Gender(String sGender) throws Exception{
    
    try{
    
    Select element= new Select(driver.findElement(By.id("Gender")));
    
    Log.info("Gender dropdown on Student Form is found.");
    
    element.selectByVisibleText(sGender);
    
    }catch (Exception e){
    
    Log.error("Gender dropdown on Student Form is not found");
    
    throw(e);
    
    }
    
    }
    
    

    Regards,
    Lakshay Sharma

    on November 10, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.