Eggplant Functional comparing a value in csv to an readtext of image

465 Views Asked by At

I am trying to complete foundation certification and on lesson 5 I needed help to complete the exercise.

I know how to read a csv (myResults) put fourth item of line 2 of myResults into color

say color value = purple

I need to select the matching radio button ( Purple, Orange, Yellow)

ReadText("Purple"), ReadText("Yellow") or ReadText("Orange")

Click allows web element, image, text, characters but not a variable. How do I do that? Need to select the correct radio button based on value in csv.

1

There are 1 best solutions below

0
sphennings On

The documentation for Eggplant Functional is confusing at the best of times but it is possible to identify the image you want to click using a variable containing a string. The click command takes a parameter called an image reference which can be an image name, image collection, image property list, or character collection. It doesn't matter to click whether the image reference is passed as a variable or as a hard coded value.

You need to create a mapping between the string you extract from the CSV and the name of the image you are wanting to click. There are many ways you could do this but one solution would be to switch on the value you extracted from the CSV and define a variable with the name if the button you want to click based on that value.

Say for the sake of argument the values you are getting from your CSV are in the form "prpl", "ylwo", and "orng", and the names of the images you are wanting to click are "purpleButton.png", "yellowButton.png", and "orangeButton.png". If this case the code to click the correct button would look something like this.

// In your actual code this value would be set from CSV
set valueFromCSV to "prpl"

if valueFromCSV is equal to "prple"
    set buttonToClick to "purpleButton.png"
else if valueFromCSV is equal to "ylwo"
    set buttonToClick to "yellowButton.png"
else if valueFromCSV is equal to "orng"
    Set buttonToClick to "orangeButton.png"
else
    error("Unable to identify color code from CSV")
end if

click buttonToClick

If you are working with a consistently designed CSV, and consistently named images it could be possible to construct the image names by manipulating the values you are extracting from the csv. For instance if the values you are getting from the CSV are "purple", "yellow", and "orange", and the images are named "purpleButton.png", "yellowButton.png", and "orangeButton.png", you could construct the names of the buttons with logic like this.

// In your actual code this value would be set from CSV
set valueFromCSV to "purple"

set buttonToClick to valueFromCSV & "Button.png"

click buttonToClick