Problem
The problem is that the if
statements are comparing apples to oranges (ie two different things). You are comparing a Watir::SelectList, from $browser.select_list(id: "title")
, with a string, from $Title2
.
For Watir elements, the ==
is used to check if two elements are the same element on the page. The element will never equal a string.
Solution
What you actually want to compare to the Title2
is the selected options of the select list. Watir select lists have a selected?
method for checking this.
You could do something like:
if $browser.select_list(id: "title").selected?($Title2)
$browser.select_list(:id, "title").select($Title1)
else
$browser.select_list(:id, "title").select($Title2)
end