testing - how to write If else condition in ruby alert box for selenium webdriver -
how write if else status in selenium alert box, here using ruby language. login page.. while come in wrong username, password.. displayed alert box , clicked on ok button.. written followed..
s = roo::excelx.new("login.xlsx") i=0 j=1 s.each |data| username = data[i] password = data[j] @driver.find_element(:id, "txtusername").clear @driver.find_element(:id, "txtusername").send_keys (username) @driver.find_element(:id, "txtpassword").clear @driver.find_element(:id, "txtpassword").send_keys (password) @driver.find_element(:id, "btnlogin").click if @driver.find_element(:xpath => "//div[9]/div/button").displayed? @driver.find_element(:xpath, "//div[9]/div/button").click else @driver.find_element(:id, "lblwelcomename").click @driver.find_element(:id, "lnklogout").click end
end
when loop started sec time, script getting stopped displayed error message
21: s = roo::excelx.new("login.xlsx") 22: i=0 23: j=1 24: s.each |data| 25: username = data[i] 26: password = data[j]
can u please help me overcome problem..
first, if you're using selenium on ruby highly recommend utilize watir webdriver instead. uses selenium under hood, it's much, much simpler , can produce understandable code it. has pretty straightforward way deal alert boxes (see this: javascript dialogs). alert boxes, want see if exist , if do, either click on or come in text , click on alert. easy watir-webdriver:
# check if alert shown browser.alert.exists? # text of alert browser.alert.text # close alert browser.alert.ok browser.alert.close javascript confirms # take confirm browser.alert.ok # cancel confirm browser.alert.close javascript prompt # come in text prompt browser.alert.set "prompt answer" # take prompt browser.alert.ok # cancel prompt browser.alert.close alternative method
you can create conditional if-then-else statements on alerts, see selenium 2.4.0, how check presence of alert inconvenient.
ruby testing selenium automation
No comments:
Post a Comment