Best Selenium code snippet using Selenium.WebDriver.switch_to
driver.rb
Source:driver.rb
...123 # This error is thrown if an unhandled alert is on the page124 # Firefox appears to automatically dismiss this alert, chrome does not125 # We'll try to accept it126 begin127 @browser.switch_to.alert.accept128 sleep 0.25 # allow time for the modal to be handled129 rescue modal_error130 # The alert is now gone131 if current_url != 'about:blank'132 begin133 # If navigation has not occurred attempt again and accept alert134 # since FF may have dismissed the alert at first attempt135 @browser.navigate.to('about:blank')136 sleep 0.1 # slight wait for alert137 @browser.switch_to.alert.accept138 rescue modal_error # rubocop:disable Metrics/BlockNesting, Lint/HandleExceptions139 # alert now gone, should mean navigation happened140 end141 end142 end143 # try cleaning up the browser again144 retry145 end146 end147 def switch_to_frame(frame)148 case frame149 when :top150 @frame_handles[browser.window_handle] = []151 browser.switch_to.default_content152 when :parent153 # would love to use browser.switch_to.parent_frame here154 # but it has an issue if the current frame is removed from within it155 @frame_handles[browser.window_handle].pop156 browser.switch_to.default_content157 @frame_handles[browser.window_handle].each { |fh| browser.switch_to.frame(fh) }158 else159 @frame_handles[browser.window_handle] ||= []160 @frame_handles[browser.window_handle] << frame.native161 browser.switch_to.frame(frame.native)162 end163 end164 def current_window_handle165 browser.window_handle166 end167 def window_size(handle)168 within_given_window(handle) do169 size = browser.manage.window.size170 [size.width, size.height]171 end172 end173 def resize_window_to(handle, width, height)174 within_given_window(handle) do175 browser.manage.window.resize_to(width, height)176 end177 end178 def maximize_window(handle)179 within_given_window(handle) do180 browser.manage.window.maximize181 end182 sleep 0.1 # work around for https://code.google.com/p/selenium/issues/detail?id=7405183 end184 def fullscreen_window(handle)185 within_given_window(handle) do186 browser.manage.window.full_screen187 end188 end189 def close_window(handle)190 raise ArgumentError, 'Not allowed to close the primary window' if handle == window_handles.first191 within_given_window(handle) do192 browser.close193 end194 end195 def window_handles196 browser.window_handles197 end198 def open_new_window199 browser.execute_script('window.open();')200 end201 def switch_to_window(handle)202 browser.switch_to.window handle203 end204 def accept_modal(_type, **options)205 yield if block_given?206 modal = find_modal(options)207 modal.send_keys options[:with] if options[:with]208 message = modal.text209 modal.accept210 message211 end212 def dismiss_modal(_type, **options)213 yield if block_given?214 modal = find_modal(options)215 message = modal.text216 modal.dismiss217 message218 end219 def quit220 @browser&.quit221 rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED # rubocop:disable Lint/HandleExceptions222 # Browser must have already gone223 rescue Selenium::WebDriver::Error::UnknownError => e224 unless silenced_unknown_error_message?(e.message) # Most likely already gone225 # probably already gone but not sure - so warn226 warn "Ignoring Selenium UnknownError during driver quit: #{e.message}"227 end228 ensure229 @browser = nil230 end231 def invalid_element_errors232 [233 ::Selenium::WebDriver::Error::StaleElementReferenceError,234 ::Selenium::WebDriver::Error::UnhandledError,235 ::Selenium::WebDriver::Error::ElementNotVisibleError,236 ::Selenium::WebDriver::Error::InvalidSelectorError, # Work around a race condition that can occur with chromedriver and #go_back/#go_forward237 ::Selenium::WebDriver::Error::ElementNotInteractableError,238 ::Selenium::WebDriver::Error::ElementClickInterceptedError,239 ::Selenium::WebDriver::Error::InvalidElementStateError,240 ::Selenium::WebDriver::Error::ElementNotSelectableError,241 ::Selenium::WebDriver::Error::ElementNotSelectableError,242 ::Selenium::WebDriver::Error::NoSuchElementError, # IE243 ::Selenium::WebDriver::Error::InvalidArgumentError # IE244 ]245 end246 def no_such_window_error247 Selenium::WebDriver::Error::NoSuchWindowError248 end249private250 def w3c?251 browser && browser.capabilities.is_a?(Selenium::WebDriver::Remote::W3C::Capabilities)252 end253 def marionette?254 firefox? && w3c?255 end256 def firefox?257 browser_name == :firefox258 end259 def chrome?260 browser_name == :chrome261 end262 def edge?263 browser_name == :edge264 end265 def ie?266 %i[internet_explorer ie].include?(browser_name)267 end268 def browser_name269 browser.browser270 end271 def native_args(args)272 args.map { |arg| arg.is_a?(Capybara::Selenium::Node) ? arg.native : arg }273 end274 def clear_storage275 if options[:clear_session_storage]276 if @browser.respond_to? :session_storage277 @browser.session_storage.clear278 else279 warn 'sessionStorage clear requested but is not available for this driver'280 end281 end282 if options[:clear_local_storage] # rubocop:disable Style/GuardClause283 if @browser.respond_to? :local_storage284 @browser.local_storage.clear285 else286 warn 'localStorage clear requested but is not available for this driver'287 end288 end289 end290 def modal_error291 Selenium::WebDriver::Error::NoSuchAlertError292 end293 def within_given_window(handle)294 original_handle = current_window_handle295 if handle == original_handle296 yield297 else298 switch_to_window(handle)299 result = yield300 switch_to_window(original_handle)301 result302 end303 end304 def find_modal(text: nil, **options)305 # Selenium has its own built in wait (2 seconds)for a modal to show up, so this wait is really the minimum time306 # Actual wait time may be longer than specified307 wait = Selenium::WebDriver::Wait.new(308 timeout: options.fetch(:wait, session_options.default_max_wait_time) || 0,309 ignore: modal_error310 )311 begin312 wait.until do313 alert = @browser.switch_to.alert314 regexp = text.is_a?(Regexp) ? text : Regexp.escape(text.to_s)315 alert.text.match(regexp) ? alert : nil316 end317 rescue Selenium::WebDriver::Error::TimeOutError318 raise Capybara::ModalNotFound, "Unable to find modal dialog#{" with #{text}" if text}"319 end320 end321 def silenced_unknown_error_message?(msg)322 silenced_unknown_error_messages.any? { |r| msg =~ r }323 end324 def silenced_unknown_error_messages325 [/Error communicating with the remote browser/]326 end327 def unwrap_script_result(arg)...
login.rb
Source:login.rb
...5 puts emailaddress6 puts ownername7 puts password8 signup(teamname,emailaddress,ownername,password)9 page.driver.browser.switch_to.alert.accept10end11Given(/^I have logged in as admin user with loginTeamName as "([^"]*)",loginEmail as "([^"]*)" and loginPassword as "([^"]*)"$/) do |team,email,password|12 ##visit("http://52.77.108.187:8000/login.html")13#Calling the log in function with team,email,password parameters from env.rb14 puts team15 puts email16 puts password17 login(team,email,password)18end19#Now Log in with the credentials using Background details from login.feature file20Given(/^I have entered valid credentials$/) do21 #click_on "Log in"22 puts "I have logged in"23end24#Modules 25Given(/^I click on Modulestab$/) do26 within ('.panel-default') do27 find(:xpath,"/html/body/div/div/div[5]/div/div[1]").click28 sleep 5 29 end30end31#Within the modules to run aws instances add module as "aws"32Given(/^I add newModules as "([^"]*)"$/) do |mod|33 click_button "New module(s) from master"34 m=page.driver.browser.switch_to.alert35 m.text == 'mod'36 m.accept37 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError38end39#Now navigated to Home page to perform other actions40Given(/^I navigate to Dashboard page$/) do41 within ('.container-fluid') do42 click_on 'strings'43 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError44 end45end46#Credentials47Given(/^now I navigated to credentials page$/) do48 find(:xpath,"/html/body/div/div/div[4]/div/div[1]").click49 click_button 'Upload Credentials'50end51#Workflows 52Given(/^I redirected to workflows page$/) do53 find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click54 click_button 'New workflow(s) from master'55 sleep 2 56 w=page.driver.browser.switch_to.alert57 w.text == 'describeEC2'58 w.accept59 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError60end61#Executing workflows62Given(/^I select describeEC workflow$/) do63 find(:xpath,"/html/body/div[2]/div/div[1]/div/div[1]").click64 sleep 1065end 66Given(/^I select Execute$/)do67 within('.btn-group')do68 click_button 'Execute'69 page.driver.browser.switch_to.alert.text == 'str'70 page.driver.browser.switch_to.alert.accept 71 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 72 end73end74Given(/^I select addModules$/)do75 within('.btn-group')do76 click_button 'Edit'77 find(:xpath,"/html/body/div/div/div/div/div[1]/div/div/ul/li[1]/a").click78 m=page.driver.browser.switch_to.alert79 m.text == 'tes'80 m.accept81 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 82 end83end84Given(/^I select removeModuless$/)do85 find(:xpath,"/html/body/div[2]/div/div[1]/div/div[1]").click86 within('.btn-group')do87 click_button 'Edit'88 find(:xpath,"/html/body/div/div/div/div/div[1]/div/div/ul/li[2]/a").click89 m=page.driver.browser.switch_to.alert90 m.text == 'tes'91 m.accept92 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 93 end94end95Given(/^I click on delete button$/)do96 find(:xpath,"/html/body/div[2]/div/div[1]/div/div[1]").click97 sleep 298 click_button 'Delete'99end100Given(/^I select deleteOne workflow$/) do101 page.find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click102 find(:xpath,"/html/body/div[2]/div/div[1]/div/div[1]").click103 within('.btn-group')do104 click_button 'Execute'105 page.driver.browser.switch_to.alert.text == ' '106 page.driver.browser.switch_to.alert.accept 107 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 108 end109end110Given(/^I select getChefUsers workflow$/) do111 page.find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click112 find(:xpath,"/html/body/div[2]/div/div[2]/div/div[1]").click113 within('.btn-group')do114 click_button 'Execute'115 page.driver.browser.switch_to.alert.text == ' '116 page.driver.browser.switch_to.alert.accept 117 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 118 end119end120Given(/^I select dropdb workflow$/) do121 page.find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click122 find(:xpath,"/html/body/div[2]/div/div[3]/div/div[1]").click123 within('.btn-group')do124 click_button 'Execute'125 page.driver.browser.switch_to.alert.text == ' '126 page.driver.browser.switch_to.alert.accept 127 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 128 end129end130Given(/^I select listRecord workflow$/) do131 page.find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click132 find(:xpath,"/html/body/div[2]/div/div[4]/div/div[1]").click133 within('.btn-group')do134 click_button 'Execute'135 page.driver.browser.switch_to.alert.text == ' '136 page.driver.browser.switch_to.alert.accept 137 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 138 end139end140Given(/^I select readTable workflow$/) do141 page.find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click142 find(:xpath,"/html/body/div[2]/div/div[5]/div/div[1]").click143 within('.btn-group')do144 click_button 'Execute'145 page.driver.browser.switch_to.alert.text == ' '146 page.driver.browser.switch_to.alert.accept 147 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 148 end149end150Given(/^I select showDB workflow$/) do151 page.find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click152 find(:xpath,"/html/body/div[2]/div/div[6]/div/div[1]").click153 within('.btn-group')do154 click_button 'Execute'155 page.driver.browser.switch_to.alert.text == ' '156 page.driver.browser.switch_to.alert.accept 157 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 158 end159end160Given(/^I select updateRecord workflow$/) do161 page.find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click162 find(:xpath,"/html/body/div[2]/div/div[7]/div/div[1]").click163 within('.btn-group')do164 click_button 'Execute'165 page.driver.browser.switch_to.alert.text == ' '166 page.driver.browser.switch_to.alert.accept 167 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 168 end169end170Given(/^I select uptime workflow$/) do171 page.find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click172 find(:xpath,"/html/body/div[2]/div/div[8]/div/div[1]").click173 within('.btn-group')do174 click_button 'Execute'175 page.driver.browser.switch_to.alert.text == ' '176 page.driver.browser.switch_to.alert.accept 177 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError 178 end179end180Given(/^I select Upload new workflow and give Workflow Name as "([^"]*)" and Workflow Code as "([^"]*)"$/)do |name,code|181 page.find(:xpath,"/html/body/div/div/div[3]/div/div[1]").click182 page.find(:xpath,"/html/body/div[1]/button[2]").click183 sleep 10184 within('.modal-content')do185 page.find(:xpath,"/html/body/div[3]/div/div/div[2]/form/div[1]/input").set 'getChefUsers'186 page.find(:xpath,"/html/body/div[3]/div/div/div[2]/form/div[2]/textarea").set 'main code'187 click_button 'Upload Workflow'188 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError189 end190end191#Users192Given(/^I click on Userstab$/) do193 within ('.panel-default')do194 page.find('.panel-heading').click195 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError196 end197end198#Selecting the new users to add199Given(/^I click on newUsers$/) do200 find(:xpath,"/html/body/div[1]/button").click201end202#Enter valid email address "testteam@gquotient.com" for the users203Given(/^I enter "([^"]*)" in browser dialog box$/) do |arg1|204 a=page.driver.browser.switch_to.alert205 a.text == 'arg1'206 a.accept207 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError208 sleep 10209end210#To edit the user details click on the user tab211Given(/^I click on user$/) do212 page.find(:xpath,"/html/body/div[2]/div/div[2]/div/div[1]").click213 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError214end215#when you redirected to user page click Edit button216Given(/^I click on Edit button$/) do217 click_button "Edit"218 sleep 2219end220#To execute workflow addWorkflows describeEC2 for the user221#Edit options in user page222Given(/^I select addWorkflows and I give describeEC2$/)do 223#To select the list element224 page.find(:xpath,"/html/body/div/div/div/div/div[1]/div/div/ul/li[1]/a").click 225 sleep 20226 w=page.driver.browser.switch_to.alert227 w.text == 'arg1'228 w.accept229 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError230 ##This will click OK on the alert if one is present, else it will fail gracefully (silently).231 #page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError232end233Given(/^I select addToGroups and group name as Strings$/)do234 page.find(:xpath,"/html/body/div[2]/div/div[2]/div/div[1]").click235 click_button "Edit"236 page.find(:xpath,"/html/body/div/div/div/div/div[1]/div/div/ul/li[2]/a").click 237 sleep 2238 g=page.driver.browser.switch_to.alert239 g.text == 'Strings'240 g.accept241 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError242end243Given(/^I select deleteWorkflows and enter describeEC2$/)do244 page.find(:xpath,"/html/body/div[2]/div/div[2]/div/div[1]").click245 click_button "Edit"246 page.find(:xpath,"/html/body/div/div/div/div/div[1]/div/div/ul/li[3]/a").click247 g=page.driver.browser.switch_to.alert248 g.text == 'describeEC2'249 g.accept250end251Given(/^I select removeFromGroups$/)do252 page.find(:xpath,"/html/body/div[2]/div/div[2]/div/div[1]").click253 click_button "Edit"254 page.find(:xpath,"/html/body/div/div/div/div/div[1]/div/div/ul/li[4]/a").click 255 g=page.driver.browser.switch_to.alert256 g.text == 'Strings'257 g.accept258end259Given(/^I select isAdmin as true$/)do260 page.find(:xpath,"/html/body/div[2]/div/div[2]/div/div[1]").click261 click_button "Edit"262 page.find(:xpath,"/html/body/div/div/div/div/div[1]/div/div/ul/li[5]/a").click 263 g=page.driver.browser.switch_to.alert264 g.text == 'true'265 g.accept266end267Given(/^I select Delete button for users$/)do268 page.find(:xpath,"/html/body/div[2]/div/div[2]/div/div[1]").click269 click_button 'Delete'270end271#Groups272Given(/^I click on Groupstab$/) do273 within ('.panel-default')do274 page.find(:xpath,"/html/body/div/div/div[2]/div/div[1]").click 275 sleep 25276 #click_button 'New group(s)'277 page.find(:xpath,"/html/body/div[1]/button").click278 sleep 5279 t=page.driver.browser.switch_to.alert280 t.text == 'Strings' 281 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError282 end283end284#Me285Given(/^I click on Me$/) do286 within ('.panel-default')do287 page.find(:xpath,"/html/body/div/div/div[6]/div/div[1]").click288 page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError289 end290end291#Logout292Then(/^I click on Log Out$/) do293within('.container-fluid')do294 click_on "Log Out"295 end296end...
Class - PrintEmail Page.rb
Source:Class - PrintEmail Page.rb
...118 wait = Selenium::WebDriver::Wait.new(:timeout => 5)119 wait.until {@driver.find_element(CANCEL_BTN).displayed?}120 cancel_button = @driver.find_element(CANCEL_BTN)121 cancel_button.click122 @driver.switch_to.default_content123 @driver.switch_to.frame(0)124 end125 def ok()126 wait = Selenium::WebDriver::Wait.new(:timeout => 5)127 wait.until {@driver.find_element(OK_BTN).displayed?}128 ok_button = @driver.find_element(OK_BTN)129 ok_button.click130 end131 #CSS Methods: Email Page132 def email_address(emailaddress)133 wait = Selenium::WebDriver::Wait.new(:timeout => 5)134 wait.until {@driver.find_element(EMAIL_ADDRESS_FIELD).displayed?}135 email_address = @driver.find_element(EMAIL_ADDRESS_FIELD)136 email_address.send_keys(emailaddress)137 end138 def email_from(emailfrom)139 wait = Selenium::WebDriver::Wait.new(:timeout => 5)140 wait.until {@driver.find_element(EMAIL_FROM_FIELD).displayed?}141 email_from = @driver.find_element(EMAIL_FROM_FIELD)142 email_from.send_keys(emailfrom)143 end144 def bcc_address(bccaddress)145 wait = Selenium::WebDriver::Wait.new(:timeout => 5)146 wait.until {@driver.find_element(BCC_ADDRESS_FIELD).displayed?}147 bcc_address = @driver.find_element(BCC_ADDRESS_FIELD)148 bcc_address.send_keys(bccaddress)149 end150 def email_subject(emailsubject)151 wait = Selenium::WebDriver::Wait.new(:timeout => 5)152 wait.until {@driver.find_element(EMAIL_SUBJECT_FIELD).displayed?}153 email_subject = @driver.find_element(EMAIL_SUBJECT_FIELD)154 email_subject.send_keys(emailsubject)155 end156 def email_message(emailmessage)157 if @driver.find_element(EMAIL_MESSAGE_FIELD).text == ""158 field_click = @driver.find_element(EMAIL_MESSAGE_FIELD)159 field_click.click160 wait = Selenium::WebDriver::Wait.new(:timeout => 5)161 wait.until {@driver.find_element(EMAIL_MESSAGE_FIELD).displayed?}162 email_message = @driver.find_element(EMAIL_MESSAGE_FIELD)163 email_message.send_keys(emailmessage)164 end165 end166 def mailing()167 wait = Selenium::WebDriver::Wait.new(:timeout => 5)168 wait.until {@driver.find_element(MAILING_CHECKBOX).displayed?}169 checkbox = @driver.find_element(MAILING_CHECKBOX)170 checkbox.click171 end172 def close()173 wait = Selenium::WebDriver::Wait.new(:timeout => 5)174 wait.until {@driver.find_element(CLOSE_BTN).displayed?}175 close_button = @driver.find_element(CLOSE_BTN)176 close_button.click177 @driver.switch_to.default_content178 @driver.switch_to.frame(0)179 end180 def back()181 wait = Selenium::WebDriver::Wait.new(:timeout => 5)182 wait.until {@driver.find_element(BACK_BTN).displayed?}183 back_button = @driver.find_element(BACK_BTN)184 back_button.click185 end186 def print()187 wait = Selenium::WebDriver::Wait.new(:timeout => 5)188 wait.until {@driver.find_element(PRINT_BTN).displayed?}189 print_button = @driver.find_element(PRINT_BTN)190 print_button.click191 end192 def email_close()193 wait = Selenium::WebDriver::Wait.new(:timeout => 5)194 wait.until {@driver.find_element(EMAIL_AND_CLOSE_BTN).displayed?}195 email_button = @driver.find_element(EMAIL_AND_CLOSE_BTN)196 email_button.click197 @driver.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError198 #wait2 = Selenium::WebDriver::Wait.new(:timeout => 5)199 #wait2.until {@driver.find_element(FRAME).displayed?}200 sleep(2)201 @driver.switch_to.default_content202 sleep(2)203 @driver.switch_to.frame(0)204 end205end...
support.rb
Source:support.rb
...14 first("a[id*='-browse-button']").click 15 within_frame("mediaBrowser") do16 attach_file("edit-upload-upload", "/home/likewise-open/CIT/kaior/img_painel_fase2/" + file)17 click_button("Upload")18 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError19 if alert != Selenium::WebDriver::Error::NoAlertOpenError then20 page.driver.browser.switch_to.alert.accept21 click_button("Upload")22 end23 wait_for_button24 click_button("Próximo")25 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError26 if alert != Selenium::WebDriver::Error::NoAlertOpenError then27 page.driver.browser.switch_to.alert.accept28 end29 30 click_button("Salvar") 31 end32 end33 def imagem_arquivos(file)34 attach_file("edit-upload-upload", "/home/likewise-open/CIT/kaior/img_painel_fase2/" + file)35 click_button("Upload")36 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError37 if alert != Selenium::WebDriver::Error::NoAlertOpenError then38 page.driver.browser.switch_to.alert.accept39 click_button("Upload")40 end41 wait_for_button42 click_button("Próximo")43 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError44 if alert != Selenium::WebDriver::Error::NoAlertOpenError then45 page.driver.browser.switch_to.alert.accept46 end47 click_button("Próximo")48 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError49 if alert != Selenium::WebDriver::Error::NoAlertOpenError then50 page.driver.browser.switch_to.alert.accept51 end52 click_button("Salvar") 53 end54 def passos(data, vnum)55 vezes = 056 for i in (1..5) do57 if data['passo' + i.to_s][vnum].to_s != "nil" then58 vezes = vezes + 159 end60 end61 62 for i in (0..vezes-1) do63 find("input[id$='steps-und-#{i}-value']").native.send_keys(data['passo' + (i+1).to_s][vnum].to_s)64 click_button("Adicionar outro item") 65 end66 end67 def imagem_conteudo_digital(data, vnum)68 vezes = 069 for i in (1..5) do70 if data['imagem' + i.to_s][vnum].to_s != "nil" then71 vezes = vezes + 172 end73 end74 for i in (1..vezes) do75 first("a[id*='-browse-button']").click 76 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError77 if alert != Selenium::WebDriver::Error::NoAlertOpenError then78 page.driver.browser.switch_to.alert.accept79 end80 within_frame("mediaBrowser") do81 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError82 if alert != Selenium::WebDriver::Error::NoAlertOpenError then83 page.driver.browser.switch_to.alert.accept84 end85 attach_file("edit-upload-upload", "/home/likewise-open/CIT/kaior/img_painel_fase2/" + data['imagem' + (i).to_s][vnum].to_s)86 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError87 if alert != Selenium::WebDriver::Error::NoAlertOpenError then88 page.driver.browser.switch_to.alert.accept89 end90 click_button("Upload")91 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError92 if alert != Selenium::WebDriver::Error::NoAlertOpenError then93 page.driver.browser.switch_to.alert.accept94 click_button("Upload")95 end96 wait_for_button97 click_button("Próximo")98 alert = page.driver.browser.switch_to.alert rescue Selenium::WebDriver::Error::NoAlertOpenError99 if alert != Selenium::WebDriver::Error::NoAlertOpenError then100 page.driver.browser.switch_to.alert.accept101 end102 click_button("Salvar") 103 end 104 sleep(1) 105 end106 end107end108World(Support)...
switch_to
Using AI Code Generation
1driver.switch_to.frame(0)2driver.find_element(:name, 'q').send_keys "hello world"3driver.find_element(:name, 'btnG').click4driver.find_element(:link_text, 'Gmail').click5driver.find_elment(:link_text, 'Gmail').click6driver.switch_to.window(driver.window_handles.last)7driver.find_element(:id, 'Email').send_keys "hello world"8driver.find_element(:id, 'signIn').click9driver.find_element(:nam,'q').send_keys "hello world"10driver.ind_element(:name, 'btnG').click11driver.find_element(:name, 'q').send_keys "hello world"12driver.find_element(:name, 'btnG').click13driver.find_element(:link_text, 'Gmail').click14driver.switch_to.window(driver.window_handles.last)15driver.find_element(:id, 'Email).send_key "hello world"16driver.find_element(:id,'sigIn').click17driver.switch_to.window(driver.window_hndles.first)
switch_to
Using AI Code Generation
1driver.switch_to.frame(0)2driver.find_element(:name, 'q').send_keys "hello world"3driver.find_element(:name, 'btnG').click4driver.find_element(:link_text, 'Gmail').click5driver.find_element(:link_text, 'Gmail').click6driver.switch_to.window(driver.window_handles.last)7driver.find_element(:id, 'Email').send_keys "hello world"8driver.find_element(:id, 'signIn').click9puts driver.find_element(:name, "btnG").attribute("value")10puts driver.find_element(:name, "q").attribute("title")11puts driver.find_element(:name, "q").attribute("value")12puts driver.find_element(:name, "q").attribute("type")13puts driver.find_element(:name, "q").attribute("name")14puts driver.find_element(:name, "q").attribute("maxlength")15puts driver.find_element(:name, "q").attribute("id")16puts driver.find_element(:name, "q").attribute("class")17puts driver.find_element(:name, "q").attribute("style")18puts driver.find_element(:name, "q").attribute("autocomplete")19puts driver.find_element(:name, "q").attribute("aria-haspopup")20pus driver.find_element(:name, "q").attribute("aria-wns")21puts driver.find_element(:n,"q").attriute("aria-autocomplete")22puts driver.find_element(:name, "q").attribute("aria-expanded")23puts driver.find_element(:name, "q").attribute("aria-activedescendant")24puts driver.find_element(:name, "q").attribute("aria-readonl")25puts driver.fid_element(:n,"q").attribute("aria-label")26puts drive.find_element(:
switch_to
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys2driver.find_element(:name, google.com"3driver.find_element(:name, 'q').send_keys "Selenium WebDriver"4driver.find_element(:name, 'btnG').click5wait = Selenium::WebDriver::Wait.ne'(:timeout => 10)6bait.until { driver.title.dotncasenstart_with? "G').clic webdriver" }
switch_to
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys 'selenium webdriver'2driver.find_element(:name, 'btnG').click3driver.switch_to.window(driver.window_handles.last)4driver.find_element(:name, 'q').send_keys 'selenium webdriver'5driver.find_element(:name, 'btnG').click6driver.switch_to.window(driver.window_handles.last)7driver.find_element(:name, 'q').send_keys 'selenium webdriver'8driver.find_element(:name, 'btnG').click9driver.switch_to.window(driver.window_handles.last)10driver.find_element(:name, 'q').send_keys 'selenium webdriver'11driver.find_element(:name, 'btnG').click12driver.switch_to.window(driver.window_handles.last)13driver.find_element(:name, 'q').send_keys 'selenium webdriver'14driver.find_element(:name, 'btnG').click15driver.switch_to.window(driver.window_handles.last)
switch_to
Using AI Code Generation
1driver.find_element(:link, "Gmail"2driver.find_element(:id, "gbqfq").send_keys "Hello World!"3driver.find_element(:name, 'q').send_keys "hello world"4driver.find_element(:name, 'btnG').click5driver.find_element(:link_text, 'Gmail').click6driver.switch_to.window(driver.window_handles.last)7driver.find_element(:id, 'Email').send_keys "hello world"8driver.find_element(:id, 'signIn').click9driver.switch_to.window(driver.window_handles.first)
switch_to
Using AI Code Generation
1driver.find_element(:link_text, 'Gmail').click2driver.switch_to.window(driver.window_handles.last)3driver.find_element(:id, 'Email').send_keys '
switch_to
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys 'selenium webdriver'2driver.find_element(:name, 'btnG').click3driver.switch_to.window(driver.window_handles.last)4driver.find_element(:name, 'q').send_keys 'selenium webdriver'5driver.find_element(:name, 'btnG').click6driver.switch_to.window(driver.window_handles.last)7driver.find_element(:name, 'q').send_keys 'selenium webdriver'8driver.find_element(:name, 'btnG').click9driver.switch_to.window(driver.window_handles.last)10driver.find_element(:name, 'q').send_keys 'selenium webdriver'11driver.find_element(:name, 'btnG').click12driver.switch_to.window(driver.window_handles.last)13driver.find_element(:name, 'q').send_keys 'selenium webdriver'14driver.find_element(:name, 'btnG').click15driver.switch_to.window(driver.window_handles.last)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!