2

Hi so currently I'm working with Selenium webdriver in Eclipse.. I'm testing a web app and having data driven from an excel sheet. There is optional information and you can click 'ADD' and then a pop up comes up. Is it possible to say something like

driver.findElement(By.xpath("ADD")).click();<br>
actions.sendkeys(SSN).perform(); 

but only have it do this if SSN data is present on the excel sheet?

6
  • Yes, it is possible. Your code needs to read/parse Excel, and execute your code only if cell contains SNN. IOW, it is pure programming problem (read and parse Excel), 100% unrelated to SQA. Apr 28 '15 at 23:29
  • 1
    I think this looks java programming related question. I understand you are working with selenium but thing you want to do can be done by java programming in your case. Apr 29 '15 at 2:45
  • Thanks. I am using java with selenium and eclipse, sorry forgot to mention this. I'm writing a script for my automation testing to test our web application which requires lots of data and many pages. I will look into your advices.
    – JohnP15
    Apr 29 '15 at 8:00
  • This is not a webdriver question. This is a basic programming question about conditionals. Voting to migrate, but also answering. Apr 29 '15 at 16:53
  • Is SSN already filled with data from Excel in earlier code? Or is this also part of the question, how do I fill SSN from Excel. Apr 29 '15 at 17:02
2

You would do this the same way you do any other conditional in Java:

if (!SSN.isEmpty()) { //Assuming SSN is a string variable 
    driver.findElement(By.xpath("ADD")).click();
    actions.sendkeys(SSN).perform();
}

This is a basic programming question; as such, I would suggest picking up a book or an online course about Java programming, as it will help you with your automation tasks.

2
  • This worked! Thanks. It was the (!SSN.isEmpty()) that i couldn't get right. And Yes I will be continuing to learn it.
    – JohnP15
    Apr 29 '15 at 17:42
  • @JohnP15 You're welcome! You can signal that this solved your problem by clicking the green checkmark next to the answer. That way it won't show up as "unanswered" anymore Apr 29 '15 at 17:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.