Best Selenium code snippet using Selenium.WebDriver.page_source
action_helper.rb
Source:action_helper.rb
2 begin3 @browser.get(url)4 wait = Selenium::WebDriver::Wait.new(:timeout => 25) # seconds5 wait.until { 6 /#{wait_for}/.match(@browser.page_source)7 }8 rescue Exception => e9 show_error(e, "visit_page(url, wait_for)", {"url" => url, "wait_for" => wait_for})10 end11end12def click_button(button, wait_for)13 begin14 wait_for_element_visible("//button[contains(.,'#{button}')]",30)15 @browser.find_element(:xpath, "//button[contains(.,'#{button}')]").location_once_scrolled_into_view16 #sleep 217 @browser.find_element(:xpath, "//button[contains(.,'#{button}')]").click18 if "#{wait_for}" == "new group name"19 #sleep 220 if @browser.find_element(:xpath,"//button[contains(.,'#{button}')]").displayed?21 @browser.find_element(:xpath, "//button[contains(.,'#{button}')]").click22 end23 end24 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds25 #sleep 226 wait.until {27 /#{wait_for}/.match(@browser.page_source) 28 }29 30 rescue Exception => e31 show_error(e, "click_button(button, wait_for)", {"button" => button, "wait_for" => wait_for})32 end33end34def click_link(link, wait_for)35 begin36 wait_for_element_visible("//a[contains(.,'#{link}')]",30)37 if link == "Add a product record using a form"38 el = @browser.find_element(:xpath, "//a[contains(.,'#{link}')]")39 sc = "arguments[0].click();"40 @browser.execute_script(sc,el)41 else42 @browser.find_element(:xpath, "//a[contains(.,'#{link}')]").click43 end44 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds45 wait.until { 46 /#{wait_for}/.match(@browser.page_source) 47 }48 49 rescue Exception => e50 show_error(e, "click_link(link, wait_for)", {"link" => link, "wait_for" => wait_for})51 end52end53def click(link)54 begin55 wait_for_element_visible("//a[contains(.,'#{link}')]",30)56 wait_for_text("#{link}")57 @browser.find_element(:xpath, "//a[contains(.,'#{link}')]").click58 59 rescue Exception => e60 show_error(e, "click(link)", {"link" => link})61 end62end63def click_bold(text)64 begin65 66 element = "//b[contains(.,'#{text}')]"67 wait_and_check(element)68 wait = Selenium::WebDriver::Wait.new(:timeout => 5)69 @browser.execute_script('arguments[0].click();', wait.until { @browser.find_element(:xpath,"//b[contains(.,'#{text}')]") })70 #sleep 571 72 rescue Exception => e73 show_error(e, "click_bold(text)", {"text" => text})74 end75end76def click_checkbox(name)77 begin78 wait_for_element_visible("//*[contains(@name,'#{name}')]",30)79 @browser.find_element(:xpath, "//*[contains(@name, '#{name}') and contains(@type, 'checkbox')]").click80 #sleep 0.581 rescue Exception => e82 show_error(e, "click_checkbox(name)", {"name" => name})83 end84end85def click_checkbox_xpath(xpath)86 begin87 wait_for_element_visible("//*[contains(@name,'#{xpath}')]",30)88 @browser.find_element(:xpath, "//*[contains(@name, '#{xpath}') and contains(@type, 'checkbox')]").click89 #sleep 0.590 rescue Exception => e91 show_error(e, "click_checkbox_xpath(xpath)", {"name" => xpath})92 end93end94def find_text(text)95 begin96 wait = Selenium::WebDriver::Wait.new(:timeout => 15) # seconds97 wait.until { 98 /#{text}/.match(@browser.page_source) 99 }100 # /#{text}/.match(@browser.page_source) # I was able to find "nomorspreadsheetssssss" in the landing page with that function, so I think something is wrong101 #@browser.find_element :xpath => "//*[contains(.,'#{text}')]"102 rescue Exception => e103 show_error(e, "find_text(text)", {"text" => text})104 end 105end106def validate_text(text, field)107 begin108 wait = Selenium::WebDriver::Wait.new(:timeout => 15) # seconds109 wait.until { 110 element = @browser.find_element :xpath => "#{field}"111 /#{text}/.match(element.text) 112 }113 114 rescue Exception => e115 show_error(e, "validate_text(text, field)", {"text" => text, "field" => field})116 end 117end118def find_label(label)119 @browser.find_element(:xpath, "//label[contains(text(),'#{label}')]")120end121def fill_in(field, data)122 begin123 #sleep 0.5124 element = @browser.find_element :xpath => "//input[@name = '#{field}']"125 element.clear126 element.send_keys(data)127 128 rescue Exception => e129 show_error(e, "fill_in(field, data)", {"field" => field, "data" => data})130 end131end132def fill_in_from_xpath(field, data)133 begin134 #sleep 0.5135 element = @browser.find_element :xpath => "#{field}"136 element.clear137 element.send_keys "#{data}"138 139 rescue Exception => e140 show_error(e, "fill_in(field, data)", {"field" => field, "data" => data})141 end142end143def fill_in_from_placeholder(placeholder, data)144 begin145 #sleep 0.5146 element = @browser.find_element :xpath => "//input[@placeholder = '#{placeholder}']"147 element.clear148 element.send_keys "#{data}"149 150 rescue Exception => e151 show_error(e, "fill_in_from_placeholder(placeholder, data)", {"placeholder" => placeholder, "data" => data})152 end153end154def fill_in_from_value(value, data)155 begin156 #sleep 0.5157 element = @browser.find_element :xpath => "//input[@value = '#{value}']"158 element.clear159 element.send_keys "#{data}"160 161 rescue Exception => e162 show_error(e, "fill_in_from_value(value, data)", {"value" => value, "data" => data})163 end164end165def select_from_dropdown(dropdown, item)166 begin167 wait_for_element_visible("//a[@placeholder='#{dropdown}']",30)168 @browser.find_element(:xpath, "//a[@placeholder='#{dropdown}']").click169 @browser.find_element(:xpath, "//span[@class='ng-binding ng-scope'][contains(text(), '#{item}')]").click170 171 rescue Exception => e172 show_error(e, "select_from_dropdown(dropdown, item)", {"dropdown" => dropdown, "item" => item})173 end174end175def select_date_from_dropdown(dropdown, item)176 begin177 wait_for_element_visible("//a[@placeholder='#{dropdown}']",30)178 @browser.find_element(:xpath, "//a[@placeholder='#{dropdown}']").click179 @browser.find_element(:xpath, "//a[contains(text(), '#{item}')]").click180 181 rescue Exception => e182 show_error(e, "select_month_from_dropdown(dropdown, item)", {"dropdown" => dropdown, "item" => item})183 end184end185def select_from_filter_dropdown(dropdown_placeholder, item)186 begin187 wait_for_element_visible("//a[contains(@class, 'select2-choice ui-select-match') and contains(@placeholder,'#{dropdown_placeholder}')]",30)188 @browser.find_element(:xpath, "//a[contains(@class, 'select2-choice ui-select-match') and contains(@placeholder,'#{dropdown_placeholder}')]").click189 #sleep(4)190 @browser.find_element(:xpath, "//*[contains(@class, 'ng-binding') and contains(text(), '#{item}')]").click191 192 rescue Exception => e193 show_error(e, "select_from_filter_dropdown(dropdown_placeholder, item)", {"dropdown_placeholder" => dropdown_placeholder, "item" => item})194 end195end196def select_option(option_list, item)197 begin198 wait_for_element_visible("//input[@name='#{option_list}']",30)199 @browser.find_element(:xpath, "//input[@name='#{option_list}']")200 @browser.find_element(:xpath, "//span[@class = 'radio-list__text' and text() = '#{item}']").click201 202 rescue Exception => e203 show_error(e, "select_option(option_list, item)", {"option_list" => option_list, "item" => item})204 end205end206def select_from_dropdown_xpath(xpath, item)207 begin208 wait_for_element_visible("#{xpath}",30)209 @browser.find_element(:xpath, "#{xpath}").click210 @browser.find_element(:xpath, "//span[@class='ng-binding ng-scope'][contains(text(), '#{item}')]").click211 212 rescue Exception => e213 show_error(e, "select_from_dropdown(xpath, item)", {"dropdown" => xpath, "item" => item})214 end215end216def upload_image(filename, wait_for)217 begin218 @browser.execute_script "window.scrollBy(0,330)"219 #sleep 3220 @browser.find_element(:xpath, "//button[contains(@class, 'btn--center btn--large') and contains(text(), 'Upload your image(s)')]").click221 222 wait1 = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds223 wait1.until { 224 @browser.find_elements(:xpath,"//iframe[@id='filepicker_dialog']").size > 0225 }226 sleep 20227 @browser.switch_to.frame 'filepicker_dialog'228 /Select a file to upload:/.match(@browser.page_source)229 base_path=File.expand_path(File.dirname(File.dirname(__FILE__)))230 value=base_path.split("features")231 path = File.absolute_path("#{value[0]}/image/#{filename}")232 233 if $os == "Windows"234 my_dir = Dir[path]235 dest_folder = path[0,2]236 file = dest_folder+"\\#{filename}"237 if !File.exist?(file)238 FileUtils.cp(my_dir, dest_folder)239 end240 241 sleep 2242 f = dest_folder + "\\#{filename}"243 elsif $os == "Linux" || $os == "Mac"244 # Just get the full path of the original image since it work in Linux245 f = path246 end247 element = @browser.find_element(:xpath,"//input[@class='fileUploadInput']")248 element.send_keys f249 sleep 4250 #this sleep time is added for letting the image upload.251 default_switch()252 sleep 20253 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds254 wait.until { 255 /#{wait_for}/.match(@browser.page_source) 256 }257 rescue Exception => e258 show_error(e, "upload_image(filename, wait_for)", {"filename" => filename, "wait_for" => wait_for})259 end260end261def visit_page_via_nav_takeover(menu_item, wait_for)262 begin263 @browser.find_element(:xpath, "//a[@class='nav-takeover__expand']").click264 sleep 2265 if /Welcome to Venzee/.match(@browser.page_source)266 ack_intercom_msg()267 end268 # This is to check if we see the big initial269 #@browser.find_element(:xpath, "//span[@class='app-profile__initials ng-binding']").displayed?270 @browser.find_element(:xpath, "//a[contains(.,'#{menu_item}')]").location_once_scrolled_into_view271 sleep 3272 #@browser.find_element(:xpath, "//a[(text()='#{menu_item}')]").click273 274 if menu_item =="Data"275 @browser.find_element(:xpath, "//a[(text()='#{menu_item}')]").click276 277 else278 @browser.find_element(:xpath, "//a[contains(.,'#{menu_item}')]").click279 end280 wait = Selenium::WebDriver::Wait.new(:timeout => 35) # seconds281 wait.until { 282 /#{wait_for}/.match(@browser.page_source)283 }284 rescue Exception => e285 show_error(e, "visit_page_via_nav_takeover(menu_item, wait_for)", {"menu_item" => menu_item, "wait_for" => wait_for})286 end287end288def upload_setting_image(filename)289 begin290 base_path=File.expand_path(File.dirname(File.dirname(__FILE__)))291 value=base_path.split("features")292 path = File.absolute_path("#{value[0]}/image/#{filename}")293 if $os == "Windows"294 my_dir = Dir[path]295 # Find the root296 dest_folder = path[0,2]297 298 # Find where the origin file is ans store the path299 file = dest_folder+"\\#{filename}"300 # Remove the file at the root if it exist301 if File.exist?(file)302 FileUtils.rm(file)303 sleep 2304 end305 # Copy the file at the root (C:\). Needed in windows cause it don't want to upload the file with the full path306 FileUtils.cp(my_dir, dest_folder)307 sleep 4308 # Prepare the image path to upload it 309 f = dest_folder+"\\#{filename}" 310 311 elsif $os == "Linux" || $os == "Mac"312 # Just get the full path of the original image since it work in Linux313 f = path314 end315 wait = Selenium::WebDriver::Wait.new(:timeout => 30)316 element = @browser.find_element(:xpath,"//input[@type='file']")317 sc = "arguments[0].style.display = 'inline';";318 # Upload the image by sending the path319 @browser.execute_script(sc,element)320 element.send_keys f321 # Can't find anything to wait for....322 sleep 1323 rescue Exception => e324 show_error(e, "upload_setting_image(filename)", {"filename" => filename})325 end326end327def validate_textbox_content(textbox, content)328 begin329 element = @browser.find_element(:name, textbox)330 assert_equal(element.attribute("value"), content)331 rescue Exception => e332 show_error(e, "validate_text_box_content(textbox, content)", {"textbox" => textbox, "content" => content})333 end334end335def validate_placeholder_content(placeholder, content)336 begin337 /#{content}/.match(@browser.find_element(:xpath, "//*[@placeholder = '#{placeholder}']"))338 rescue Exception => e339 show_error(e, "validate_placeholder_content(placeholder, content)", {"placeholder" => placeholder, "content" => content})340 end341end342def validate_textbox_content_via_ngmodel(ng_model, content)343 begin344 element = @browser.find_element(:css, "input[ng-model='#{ng_model}']")345 assert_equal(element.attribute("value"), content)346 rescue Exception => e347 show_error(e, "validate_text_box_content(textbox, content)", {"ng_model" => ng_model, "content" => content})348 end349end350def validate_image(filename)351 begin352 element = @browser.find_element(:css, "div[class='file-dragdrop__thumb-default ng-scope']")353 # Remove the .jpg extention because 'style' include the name from the server which include a random id before the .jpg354 filename = filename[0, filename.length-4]355 assert_exist_in(filename, element.attribute("style").to_s)356 rescue Exception => e357 show_error(e, "validate_image(filename)", {"filename" => filename})358 end359end360def validate_dropdown(dropdown, item)361 begin362 @browser.find_element(:xpath, "//span[@class='ng-binding ng-scope'][contains(text(), '#{item}')]")363 rescue Exception => e364 show_error(e, "validate_dropdown(dropdown, item)", {"dropdown" => dropdown, "item" => item})365 end366end367def assert_equal(text,content)368 begin369 if text.to_s != content.to_s370 raise "Expect '#{content}', got '#{text}'"371 end372 rescue Exception => e373 show_error(e, "assert_equal(text,content)", {"text" => text, "content" => content})374 end375end376def assert_exist_in(text, text_to_look_in)377 begin378 379 if (text_to_look_in.include? text) == false380 raise "Cant find '#{text}' in '#{text_to_look_in}'"381 end382 rescue Exception => e383 show_error(e, "assert_exist_in(text, text_to_look_in)", {"text" => text, "text_to_look_in" => text_to_look_in})384 end385end386def click_by_ng(value,wait_for)387 begin388 wait_for_element_visible("//*[contains(@ng-click,'#{value}')]",20)389 @browser.find_element(:xpath, "//*[contains(@ng-click,'#{value}')]").click390 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds391 wait.until { 392 /#{wait_for}/.match(@browser.page_source) 393 }394 rescue Exception => e395 show_error(e, "click_by_ng(value, wait_for)", {"value" => value,"wait_for "=> wait_for})396 end397end398def click_input(value)399 begin400 wait_for_element_visible("//input[contains(@value,'#{value}')]",20)401 @browser.find_element(:xpath, "//input[contains(@value,'#{value}')]").click402 rescue Exception => e403 show_error(e, "click_input(value)", {"value" => value})404 end405end406def switch_frame(id,wait_for)407 begin408 @browser.switch_to.frame "#{id}"409 wait = Selenium::WebDriver::Wait.new(:timeout => 35) # seconds410 wait.until { 411 /#{wait_for}/.match(@browser.page_source) 412 }413 414 rescue Exception => e415 show_error(e, "switch_frame(id, wait_for)", {"id" => id, "wait_for" => wait_for})416 end417end418def default_switch()419 begin420 @browser.switch_to.default_content421 rescue Exception => e422 show_error(e, "default_content()")423 end424end425def switch_tab(wait_for)426 begin427 @browser.switch_to.window(@browser.window_handles.last)428 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds429 wait.until { 430 /#{wait_for}/.match(@browser.page_source) 431 }432 433 rescue Exception => e434 show_error(e, "switch_tab(wait_for)", {"wait_for" => wait_for})435 end436end437def element_is_available(element)438begin439 expect(@browser.find_element(:xpath,"//*[contains(@class,'#{element}')]").displayed?.to_s)=="true"440 rescue Exception => e441 show_error(e, "element_is_available(element)", {"element" => element})442 end443end444def element_not_available(field)445 begin446 @browser.find_element(:xpath,"//*[contains(.,'#{field}')]").displayed?.to_s.should=="false"447 448 449 rescue Exception => e450 show_error(e, "element_not_displayed(field)", {"field" => field})451 end452end453def visit(url, wait_for)454 begin455 @browser.get "#{@base_url}"+"/"+"#{url}"456 for i in 0..2457 wait = Selenium::WebDriver::Wait.new(:timeout => 90) # seconds458 wait.until { 459 /#{wait_for}/.match(@browser.page_source)460 }461 end462 rescue Exception => e463 show_error(e, "visit(url, wait_for)", {"url" => url, "wait_for" => wait_for})464 end465end466def wait_and_refresh(sec)467 @browser.navigate.refresh468 begin469 @browser.navigate.refresh470 sleep sec471 rescue Exception => e472 show_error(e, "wait_and_refresh(sec)", {"sec" => sec})473 end474end475def wait_for_element_enabled(arg1)476 begin477 #wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds478 #wait.until { 479 # elementValue = @browser.find_element(:xpath,"//fieldset[contains(@ng-disabled, 'isSubmitting')and contains(@ng-init, '#{arg1}')]")480# value = el.attribute('disabled')481 # !elementValue.attribute('disabled') 482 sleep 20483 #}484 rescue Exception => e485 show_error(e, "wait_for_element_enabled(arg1)", {"arg1" => arg1})486 end487end488def text_not_available(text)489 begin490 puts "check if the group still visisble"491 /#{text}/.match(@browser.page_source).to_s.should==""492 rescue Exception => e493 show_error(e, "text_not_available(text)", {"text" => text})494 end495end496def list_not_available(text)497 begin498 puts "check if the group still visisble"499 sleep 10500 #/#{text}/.match(@browser.page_source).to_s.should==""501 @browser.find_element(:xpath,"//li[contains(.,'#{text}')]").displayed?.to_s.should=="false"502 rescue Exception => e503 show_error(e, "text_not_available(text)", {"text" => text})504 end505end506def press_key(field,key,wait_for)507 begin508 @browser.find_element(:xpath, "//input[contains(@class,'#{field}')]").send_keys key509 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds510 wait.until { 511 /#{wait_for}/.match(@browser.page_source)512 }513 rescue Exception => e514 show_error(e, "press_key(field,key,wait_for)",{"field" => field, "key" => key, "wait_for" => wait_for})515 end516end517def click_by_xpath(xpath)518 begin519 wait_for_element_visible(xpath, 30)520 @browser.find_element(:xpath, "#{xpath}").click521 rescue Exception => e522 show_error(e, "click_by_xpath(xpath)", {"xpath" => xpath})523 end524end525def wait_and_check(element)526 begin527 is_email_found = false528 529 puts "entering wait_and_check(): #{element}"530 for i in 0..5531 element_size = @browser.find_elements(:xpath, "#{element}").size532 puts "element_size size : #{element_size}"533 if element_size > 0534 if @browser.find_element(:xpath,"#{element}").displayed?.to_s535 puts "Email is Visible"536 is_email_found = true537 break538 else539 puts "Email is Not visible"540 541 end542 543 else544 puts "Refreshing the browser and wait 10 sec"545 @browser.navigate.refresh546 sleep 5547 548 end549 550 end551 552 # If email hasn'T been found, raise an error553 if is_email_found554 puts "exiting wait_and_check() cause email has been found"555 else556 raise "The following email hasn't been found : #{element}"557 end558 rescue Exception => e559 puts "crash wait_and_check()"560 show_error(e, "wait_and_check(element)", {"element" => element})561 end562end563def verifyAlert()564 begin565 a = @browser.switch_to.alert566 if a.text == 'Are you sure'567 a.dismiss568 else569 a.accept570 end571 572 rescue Exception => e573 show_error(e,"verifyAlert()",{})574 end575end576def wait_for_element_visible(element,timeout)577 begin578 for i in 0..timeout579 element_size = @browser.find_elements(:xpath, "#{element}").size580 if element_size > 0581 if @browser.find_element(:xpath,"#{element}").displayed?.to_s582 break583 else584 puts "Element is not visible"585 end586 else587 sleep 1588 end589 end 590 rescue Exception => e591 show_error(e,"wait_for_element_visible(element,timeout)", {"element" => element, "timeout" => timeout})592 end593end594def fill_in_text_area(field, data)595 begin596 sleep 0.5597 element = @browser.find_element :xpath => "//textarea[@name = '#{field}']"598 element.clear599 element.send_keys "#{data}"600 601 rescue Exception => e602 show_error(e, "fill_in(field, data)", {"field" => field, "data" => data})603 end604end605def click_by_xpath_wait(xpath,wait_for)606 begin607 sleep 0.5608 @browser.find_element(:xpath, "#{xpath}").click609 wait = Selenium::WebDriver::Wait.new(:timeout => 50) # seconds610 wait.until { 611 /#{wait_for}/.match(@browser.page_source) 612 }613 rescue Exception => e614 show_error(e, "click_by_xpath(xpath)", {"xpath" => xpath})615 end616end617def select_time(dropdown,value)618 begin619 sleep 0.5620 @browser.find_element(:xpath, "//a[@placeholder='#{dropdown}']").click621 wait = Selenium::WebDriver::Wait.new(:timeout => 50) # seconds622 wait.until { 623 /#{value}/.match(@browser.page_source)624 }625 @browser.find_element(:xpath,"//a[contains(text(),'#{value}')]").click626 627 rescue Exception => e628 show_error(e, "select_time(dropdown,value)", {"dropdown" => dropdown, "value" => value})629 end630end631def wait_for_text(text)632 begin633 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds634 wait.until { 635 /#{text}/.match(@browser.page_source) 636 }637 rescue Exception => e638 show_error(e, "wait_for_text(text)", {"text" => text})639 end640end641def click_by_java(button, wait_for)642 begin643 wait_for_element_visible("//button[contains(.,'#{button}')]",30)644 element = @browser.find_element(:xpath, "//button[contains(.,'#{button}')]").click645 sc = "arguments[0].click();"646 @browser.execute_script(sc,element)647 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds648 wait.until {649 /#{wait_for}/.match(@browser.page_source) 650 }651 652 rescue Exception => e653 show_error(e, "click_button(button, wait_for)", {"button" => button, "wait_for" => wait_for})654 end655end656def assert_element_present(elem_locator)657 begin658 if @browser.find_elements(elem_locator).size() <= 0659 raise "'#{elem_locator}' NOT present on the page"660 end661 rescue Exception => e662 show_error(e, "assert_element_present(elem_locator)", {"elem_locator" => elem_locator})663 end664end665def is_element_present(elem_locator)666 begin667 @browser.find_element(elem_locator)668 return true669 670 rescue Exception => e671 return false 672 end673end674def click_if_present(elem_locator)675 begin676 wait_for_element_visible(xpath, 5)677 if is_element_present(elem_locator)678 @browser.find_element(elem_locator).click679 end680 rescue Exception => e681 show_error(e, "click_if_present(elem_locator)", {"elem_locator" => elem_locator})682 end683end684def assert_text_not_present(text)685 begin686 sleep 5687 if @browser.page_source.include? text688 raise "'#{text}' displayed on the page"689 end690 rescue Exception => e691 show_error(e, "assert_text_not_present(text)", {"text" => text})692 end693end694def execute_js(js)695 begin696 @browser.execute_script(js)697 698 rescue Exception => e699 show_error(e, "execute_js(js)", {"js" => js})700 end701end702def get_text(elem_locator)703 begin704 text = @browser.find_element(elem_locator).text.strip705 return text706 707 rescue Exception => e708 show_error(e, "get_text(elem_locator)", {"elem_locator" => elem_locator})709 end710end711def press_key(key)712 begin713 @browser.action.send_keys(key).perform714 715 rescue Exception => e716 show_error(e, "press_keys(key)", {"key" => key})717 end718end719def mouse_Hover(elem_locator)720 begin721 el = @browser.find_element(:xpath, "#{elem_locator}")722 @browser.action.move_to(el).perform723 rescue Exception => e724 show_error(e, "mouse_Hover(key)", {"key" => elem_locator})725 end726end 727def click_btn(button)728 begin729 wait_for_element_visible("//button[contains(.,'#{button}')]",30)730 wait_for_text("#{button}")731 @browser.find_element(:xpath, "//button[contains(.,'#{button}')]").click732 rescue Exception => e733 show_error(e, "click_btn(button)", {"button" => button})734 end735end736def upload_bulk_image(filename, wait_for)737 begin738 @browser.execute_script "window.scrollBy(0,330)"739 #sleep 3740 @browser.find_element(:xpath, "//button[contains(@class, 'btn btn--large') and contains(text(), 'Upload your image(s)')]").click741 742 wait1 = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds743 wait1.until { 744 @browser.find_elements(:xpath,"//iframe[@id='filepicker_dialog']").size > 0745 }746 sleep 20747 @browser.switch_to.frame 'filepicker_dialog'748 /Select a file to upload:/.match(@browser.page_source)749 base_path=File.expand_path(File.dirname(File.dirname(__FILE__)))750 value=base_path.split("features")751 path = File.absolute_path("#{value[0]}/image/#{filename}")752 753 if $os == "Windows"754 my_dir = Dir[path]755 dest_folder = path[0,2]756 file = dest_folder+"\\#{filename}"757 if !File.exist?(file)758 FileUtils.cp(my_dir, dest_folder)759 end760 761 sleep 2762 f = dest_folder + "\\#{filename}"763 elsif $os == "Linux" || $os == "Mac"764 # Just get the full path of the original image since it work in Linux765 f = path766 end767 element = @browser.find_element(:xpath,"//input[@class='fileUploadInput']")768 element.send_keys f769 sleep 4770 #this sleep time is added for letting the image upload.771 default_switch()772 sleep 20773 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds774 wait.until { 775 /#{wait_for}/.match(@browser.page_source) 776 }777 rescue Exception => e778 show_error(e, "upload_bulk_image(filename, wait_for)", {"filename" => filename, "wait_for" => wait_for})779 end780end...
all_steps.rb
Source:all_steps.rb
...17 end18 ele=@driver.find_element(:id, "go")19 ele.click20 rescue21 if @driver.page_source.match('SLI Exception')22 ele=false23 puts "SLI Exception"24 elsif Timeout::Error25 puts "TimeOut error"26 else27 raise Selenium::WebDriver::Error::NoSuchElementError28 end29 end30 31end32Then /^I follow all the wsrp links$/ do33 begin34 wsrp_elements= []35 # wsrp_elements=@driver.find_elements(:xpath, "//section [@id='portlet_appselectioninterfaceportlet_WAR_AppSelectionInterfaceportlet']/div/div/div/table/tbody/tr/td/a")36 @driver.find_elements(:xpath, "//a[@href='#']").each do |tt|37 if tt.attribute('onclick') != nil && tt.attribute('onclick').match('callWsrp')38 wsrp_elements << tt39 end40 end41 wsrp_elements.compact!42 wsrp_ele=[]43 wsrp_elements.each do |wsrp|44 wsrp_ele << wsrp.attribute('onclick').gsub("callWsrp","").gsub("(","").gsub(")","").gsub("'","")45 end46 47 wsrp_ele.each do |el|48 @driver.navigate.to el49 puts "successfully open all the #{el} WSRP Page"50 end51 52 53 54 rescue55 if @driver.page_source.match('SLI Exception')56 ele=false57 puts "SLI Exception"58 elsif Timeout::Error59 puts "TimeOut error"60 else61 raise Selenium::WebDriver::Error::NoSuchElementError62 end63 end64 65end66Then /^I am on the wsrp page$/ do67 begin68 text=@driver.find_element(:tag_name => "title").text()69 puts text70 rescue71 if @driver.page_source.match('SLI Exception')72 ele=false73 puts "SLI Exception"74 elsif Timeout::Error75 puts "TimeOut error"76 else77 raise Selenium::WebDriver::Error::NoSuchElementError78 end79 end80end81Then /^I select "([^\"]*)" from "([^\"]*)"$/ do |text,field|82 begin83 #wait = Selenium::WebDriver::Wait.new(:timeout => 10)84 # wait.until{85 a=@driver.find_element(:id, field)86 options=a.find_elements(:tag_name=>"option")87 options.each do |g|88 if g.attribute('value') == text || g.text == text89 g.click90 break91 end92 end93 # }94 rescue95 if @driver.page_source.match('SLI Exception')96 ele=false97 puts "SLI Exception"98 elsif Timeout::Error99 puts "TimeOut error"100 else101 raise Selenium::WebDriver::Error::NoSuchElementError102 end103 end104end105Then /^I click "([^\"]*)"$/ do |btn_text|106 begin107 ele=@driver.find_element(:id, "go")108 ele.click109 rescue110 if @driver.page_source.match('SLI Exception')111 ele=false112 puts "SLI Exception"113 elsif Timeout::Error114 puts "TimeOut error"115 else116 raise Selenium::WebDriver::Error::NoSuchElementError117 end118 end119 #@driver.find_element(:xpath, "//form/input[@value=#{btn_text}]").click120end 121Given /^EULA has been accepted$/ do122end123When /^I go to the login page$/ do124 @driver.navigate.to "https://devlycans.slidev.org/portal"125 begin126 a=@driver.find_element(:name,'realmId') #realmId should be the html tag name of select tag127 ele=true128 if ele == true129 options=a.find_elements(:tag_name=>"option") # all the options of that select tag will be selected130 options.each do |g|131 if g.attribute('value') == '5a4bfe96-1724-4565-9db1-35b3796e3ce1'132 g.click133 break134 end135 end136 ele=@driver.find_element(:id, "go")137 ele.click138 end139 rescue140 if @driver.page_source.match('SLI Exception')141 ele=false142 puts "SLI Exception"143 elsif Timeout::Error144 puts "TimeOut error"145 else146 raise Selenium::WebDriver::Error::NoSuchElementError147 end148 end149 150 151end152Then /^I follow the home page Dashboard$/ do 153 begin154 element= @driver.find_element(:xpath, "//td/a/div[text()=' Dashboard (Integration)']")155 element.click156 rescue157 if @driver.page_source.match('SLI Exception')158 ele=false159 puts "SLI Exception"160 elsif Timeout::Error161 puts "TimeOut error"162 else163 raise Selenium::WebDriver::Error::NoSuchElementError164 end165 end166end167Then /^I should logged out$/ do168 #begin169 #@driver.find_element(:link, 'Sign Out').click170 #rescue171 begin172 173 174 #action=Selenium::WebDriver::ActionBuilder.new(:move_to,nil)175 wait = Selenium::WebDriver::Wait.new(:timeout => 10) 176 wait.until{177 menu = @driver.find_elements(:class,"menulink").first.click()178 submenu=@driver.find_element(:link, 'Logout')179 submenu.click }180 #@driver.action.move_to(menu).perform181 rescue182 183 if @driver.page_source.match('SLI Exception')184 ele=false185 puts "SLI Exception"186 elsif Timeout::Error187 puts "TimeOut error"188 else189 raise Selenium::WebDriver::Error::NoSuchElementError190 end191 192 end193 #submenu=@driver.find_element(:link, 'Logout')194 195 #@driver.action.move_to(menu).click(submenu).perform196 197 #click_link('Logout')198end199Then /^I should be on the home page$/ do200 begin201 ele=@driver.find_element(:xpath, "//input[@value='Agree']")202 element=true203 rescue204 element=false205 end206 if element207 ele.click208 else209 puts "EULA has already been accepted"210 end211 begin212 213 #action=Selenium::WebDriver::ActionBuilder.new(:move_to,nil)214 #@driver.action.move_to(menu).perform215 wait = Selenium::WebDriver::Wait.new(:timeout => 10) 216 wait.until{217 menu = @driver.find_elements(:class,"menulink").first.click()218 submenu=@driver.find_element(:link, 'Logout').displayed? }219 rescue Selenium::WebDriver::Error::NoSuchElementError, Timeout::Error, NoMethodError220 if @driver.page_source.match('SLI Exception')221 ele=false222 puts "SLI Exception"223 elsif Timeout::Error224 puts "TimeOut error"225 elsif NoMethodError226 puts ""227 else228 raise Selenium::WebDriver::Error::NoSuchElementError229 end230 end231 #submenu=@driver.find_element(:link, 'Logout').displayed?232 233 234 #@driver.find_element(:link, 'Sign Out').displayed?235end236And /^I see the EULA Page$/ do237 begin238 ele=@driver.find_element(:xpath, "//input[@value='Agree']")239 ele2=@driver.find_element(:xpath, "//input[@value='Logout']")240 element=true241 rescue242 element=false243 end244 if element == true245 true246 else247 puts "SLI Exception"248 end 249end250When /^I mouseover on menu and click submenu "([^\"]*)"$/ do |submenu|251 begin252 253 #action=Selenium::WebDriver::ActionBuilder.new(:move_to,nil)254 #@driver.action.move_to(menu).perform255 wait = Selenium::WebDriver::Wait.new(:timeout => 10)256 wait.until{257 menu = @driver.find_elements(:class,"menulink").first.click()258 @driver.find_element(:link, submenu).click()}259 rescue260 if @driver.page_source.match('SLI Exception')261 ele=false262 puts "SLI Exception"263 elsif Timeout::Error264 puts "TimeOut error"265 else266 raise Selenium::WebDriver::Error::NoSuchElementError267 end268 end269 #submenu=@driver.find_element(:link, 'Logout')270 # submenu.click271 272end273Given /^I should remove all cookies$/ do274 @driver.manage.delete_all_cookies275end276When /^I login with "([^\"]*)" and "([^\"]*)"$/ do |username, password|277 begin278 @driver.manage.delete_all_cookies279 element = @driver.find_element(:id, 'IDToken1') #the username field id is IDToken1280 element.send_keys username281 element = @driver.find_element(:id, 'IDToken2') #the username field id is IDToken2282 element.send_keys password283 element=@driver.find_element(:class, "Btn1Def")284 element.click285 rescue286 if @driver.page_source.match('SLI Exception')287 ele=false288 puts "SLI Exception"289 elsif Timeout::Error290 puts "TimeOut error"291 else292 raise Selenium::WebDriver::Error::NoSuchElementError293 end294 end295 #wait = Selenium::WebDriver::Wait.new(:timeout => 100) # seconds296 # wait.until { driver.find_element(:link => "Logout") }297end298Then /^I should be on the authentication failed page$/ do299 begin300 @driver.navigate.to "https://devopenam1.slidev.org:80/idp2/UI/Login"301 rescue302 303 if @driver.page_source.match('SLI Exception')304 ele=false305 puts "SLI Exception"306 elsif Timeout::Error307 puts "TimeOut error"308 else309 raise Selenium::WebDriver::Error::NoSuchElementError310 end311 end312 313end314Then /^I click button "([^\"]*)"$/ do |text|315 begin316 wait = Selenium::WebDriver::Wait.new(:timeout => 100)317 wait.until { @driver.find_element(:xpath, "//span/input[@value='#{text}']")318 @driver.find_element(:xpath, "//span/input[@value='#{text}']").click319 320 }321 322 rescue323 if @driver.page_source.match('SLI Exception')324 ele=false325 puts "SLI Exception"326 elsif Timeout::Error327 puts "TimeOut error"328 else329 raise Selenium::WebDriver::Error::NoSuchElementError330 end331 end332 333end334Then /^I should be on the admin page$/ do335 #begin336 #wait = Selenium::WebDriver::Wait.new(:timeout => 10)337 #wait.until{338 if @driver.find_element(:link, "Admin").displayed? 339 puts "On the admin Page"340 else341 puts "Not an admin Page"342 end343 # }344 345 #rescue346 #if @driver.page_source.match('SLI Exception')347 # ele=false348 # puts "SLI Exception"349 # elsif Timeout::Error350 # puts "TimeOut error"351 # else352 # raise Selenium::WebDriver::Error::NoSuchElementError353 # end354 #end355end356And /^I select the "([^\"]*)"$/ do |sel|357 #wait = Selenium::WebDriver::Wait.new(:timeout => 10)358 #wait.until{359 select=@driver.find_element(:tag_name, 'select')360 options=select.find_elements(:tag_name, "option")361 options.each do |g|362 if g.attribute('value') == sel363 g.click364 break365 end366 end367end368And /^I click "([^\"]*)"$/ do |btn|369 370 371end372Then /^It open a popup$/ do373 wait = Selenium::WebDriver::Wait.new(:timeout => 10)374 wait.until{375 frame=@driver.find_element(:tag_name, "iframe")376 @driver.switch_to.frame(frame)377 378 }379 380end381Then /^I should see "([^"]*)" as "([^"]*)"$/ do |field,text|382 begin383 if @driver.find_element(:id, field).text == text384 val=true385 else386 val=false387 puts "DEFECT:-The Description text box retains earlier text after reporting a problem"388 end389 390 rescue391 if @driver.page_source.match('SLI Exception')392 ele=false393 puts "SLI Exception"394 elsif Timeout::Error395 puts "TimeOut error"396 else397 raise Selenium::WebDriver::Error::NoSuchElementError398 end399 end400 401end402Then /^I fill "([^"]*)" from "([^"]*)"$/ do |arg1, arg2|403 begin404 @driver.find_element(:id, arg2).send_keys arg1405 rescue Selenium::WebDriver::Error::NoSuchElementError, Timeout::Error406 if @driver.page_source.match('SLI Exception')407 ele=false408 puts "SLI Exception"409 elsif Timeout::Error410 puts "TimeOut error"411 elsif Selenium::WebDriver::Error::NoSuchElementError412 puts ""413 else414 puts ""415 # raise Selenium::WebDriver::Error::NoSuchElementError416 end417 end418end419Then /^I close the browser$/ do420 @driver.quit421end422Then /^(?:|I )should see "([^\"]*)"$/ do |text|423 begin424 link=@driver.find_element(:link, text).displayed? || @driver.find_element(:name, text).displayed?425 link=true426 rescue427 link=false428 end429 link 430 431end432Then /^(?:|I )should not see "([^\"]*)"$/ do |text|433 begin434 link=@driver.find_element(:link, text).displayed? || @driver.find_element(:name, text).displayed?435 link=true436 rescue437 link=false438 end 439 link440 441end442When /^(?:|I )follow "([^\"]*)"$/ do |link|443 begin444 @driver.find_element(:link, link).click445 rescue446 if @driver.page_source.match('SLI Exception')447 ele=false448 puts "SLI Exception"449 elsif Timeout::Error450 puts "TimeOut error"451 else452 raise Selenium::WebDriver::Error::NoSuchElementError453 end454 end455 456end...
empire.rb
Source:empire.rb
...52 Headless.ly do53 results_count_string = nil54 caps = Selenium::WebDriver::Remote::Capabilities.firefox55 caps['acceptInsecureCerts'] = true56 page_source = nil57 @driver = Selenium::WebDriver.for :firefox, desired_capabilities: caps58 begin59 @driver.navigate.to url60 @wait.until do61 begin62 page_source = @driver.page_source63 results_count = @driver.find_element(css: "div[data-test='results-count-greater-than-one']")64 results_count_string = results_count.text65 rescue Selenium::WebDriver::Error::NoSuchElementError => e66 # Are we on an empty results page?67 @driver.find_element(id: "results-container")68 end69 true70 end71 @driver.quit72 rescue Exception => e73 # Make sure we quit the browser even if we run into an exception we didn't anticipate74 @driver.quit75 raise e76 end77 if results_count_string78 puts "Found results_count_string: #{results_count_string}"79 results_count_match = results_count_string.match(/\s+of\s+([0-9,]+)\s+results/)80 return results_count_match[1].gsub(',', '').to_i81 else82 STDOUT.puts "Error searching for record limit"83 STDOUT.puts page_source.gsub("\n", " ")84 raise NoRecordLimitFoundError.new("No record limit found for URL")85 end86 end87 end88 end89 end90 end91end...
greenhouse.rb
Source:greenhouse.rb
...8 def self.supports?(page)9 DOMAIN_REGEXP.match?(page)10 end11 def find(options = nil)12 page_source = download(page)13 gh_token = extract_token(page_source)14 count = if gh_token15 parse_json(download("https://boards-api.greenhouse.io/v1/boards/#{gh_token}/jobs"))['jobs'].count16 else17 extract_js(url)18 end19 count == 0 ? [] : count.times.map { |i| Posting.new("Greenhouse Stub #{i}") }20 end21 private22 def parse_json(doc)23 JSON.parse(doc)24 rescue JSON::ParseError => e25 raise Error, "failed to parse JSON: #{e}"26 end27 def extract_token(page_source)28 nok = parse(page_source)29 greenhouse_links = nok.css('a').map{|x|x.attr('href')}.select{|x|x.include?('greenhouse.io')}30 greenhouse_iframes = nok.css('iframe').map{|x|x.attributes['src'].value}.select{|x|x.include?('grnh.se')}31 if greenhouse_links.count > 032 token = greenhouse_links.first.match(/greenhouse.io\/([^\/]+)\//)[1]33 elsif greenhouse_iframes.count > 034 # FIXME: Catch errors35 parsed = URI.parse(FinalRedirectUrl.final_redirect_url(greenhouse_iframes.first))36 parsed.fragment = parsed.query = nil # get rid of the query string parameters37 token = parsed.to_s.split('boards.greenhouse.io/').last38 else39 begin40 token = nok.css('meta[property="og:url"]').attr('content').value.split('boards.greenhouse.io/').last41 if token.match(/https?:/)42 token = get_token_from_script_tag(nok)...
user_registration_test.rb
Source:user_registration_test.rb
...45 'label_preferedProgrammingLanguage_data').text46 assert "true" == @driver.find_element(:id, 'label_acceptAdds_data').text47 @driver.save_screenshot("./target/nativeScreen02.png")48 puts "The source of current screen:"49 page_source = JSON.pretty_generate( @driver.page_source)50 write_to_file( page_source )51 #goto main screen52 @driver.find_element(:id, 'buttonRegisterUser').click53 end54 def setup55 caps = Selenium::WebDriver::Remote::Capabilities.android56 caps.version = "5"57 caps.platform = :linux58 caps.proxy = nil59 caps[:aut] = "io.selendroid.testapp:0.5.0-SNAPSHOT"60 caps[:locale]="de_DE"61 caps[:browserName]="selendroid"62 @driver = Selenium::WebDriver.for(63 :remote,64 :url => "http://localhost:5555/wd/hub",...
aetna_crawler.rb
Source:aetna_crawler.rb
...11 schedule_scrape(plan_id, url)12 return13 end14 end15 page_source = nil16 Headless.ly do17 @driver = Selenium::WebDriver.for_firefox_with_proxy18 begin19 @driver.navigate.to "http://www.aetna.com/dse/search?site_id=dse&langPref=en"20 @wait.until do21 @driver.find_element(id: "searchType")22 sleep 223 end24 @driver.execute_script("window.open()")25 @driver.switch_to.window(@driver.window_handles.last)26 @driver.navigate.to url27 @wait.until do28 begin29 # Did we find any results?30 @driver.find_element(id: "pageNumbers")31 true32 rescue Selenium::WebDriver::Error::ServerError => e33 unless e.message =~ /404/34 raise e35 end36 rescue Selenium::WebDriver::Error::NoSuchElementError => e37 # Are we on an empty results page?38 @driver.find_element(id: "noResultsSection")39 true40 end41 end42 begin43 # Did we find any results?44 @driver.find_element(id: "pageNumbers")45 # we need to strip out tabs and newlines here since they mess with ssdb-rb's GET method46 # might as well get rid of extra space characters while we're at it47 page_source = @driver.page_source48 self.ssdb.set(url, sanitize_for_ssdb(page_source))49 schedule_scrape(plan_id, url)50 rescue Selenium::WebDriver::Error::NoSuchElementError => e51 STDOUT.puts("No results found for [#{plan_id}, #{url}]")52 end53 @driver.quit54 rescue Exception => e55 # Make sure we quit the browser even if we run into an exception we didn't anticipate56 puts @driver.page_source57 @driver.quit58 raise e59 end60 end61 end62 63 def self.schedule_scrape plan_id, url64 STDOUT.puts("Enqueueing AetnaScraper with [#{plan_id}, #{url}]")65 Resque.push('scraper_aetna', :class => 'Jobs::Scrapers::AetnaScraper', :args => [plan_id, url])66 end67 end68 end69end...
scalper.rb
Source:scalper.rb
...20# rescue Selenium::WebDriver::Error::NoSuchElementError21# retry22# end23# end24# Nokogiri::HTML(@driver.page_source)25# end26# # Load a thread by URL27# #28# # @param url [Integer] a url to a thread29# # @return [Nokogiri::HTML]30# def thread(url)31# @driver.navigate.to url32# wait = Selenium::WebDriver::Wait.new(timeout: 60)33# wait.until do34# begin35# @driver.find_element(css: "div#thread_#{url.scan(/\d+/).last}").displayed?36# rescue Selenium::WebDriver::Error::NoSuchElementError37# retry38# end39# end40# Nokogiri::HTML(@driver.page_source)41# end42# end43# end44module Meta45 # Extract data from pages46 class Scalper47 # Create a client to extrat data from site48 #49 # param driver [Selenium::WebDriver]50 def initialize(driver)51 @driver = driver52 end53 # Load HTML page from some54 #55 # @param url [String] a url to a catalog page56 # @return [Nokogiri::HTML]57 def catalog(url)58 @driver.navigate.to url59 page_loaded?(@driver, 'div.threads')60 Nokogiri::HTML(@driver.page_source) # if page_loaded?(@driver, 'div.threads')61 end62 # Load a thread by URL63 #64 # @param url [Integer] a url to a thread65 # @return [Nokogiri::HTML]66 def thread(url)67 @driver.navigate.to url68 page_loaded?(@driver, "div#thread_#{url.scan(/\d+/).last}")69 Nokogiri::HTML(@driver.page_source) # if page_loaded?(@driver, "div#thread_#{url.scan(/\d+/).last}")70 end71 private72 def page_loaded?(driver, element, timeout = 60, interval = 2)73 wait = Selenium::WebDriver::Wait.new(timeout: timeout, interval: interval)74 begin75 wait.until { driver.find_element(css: element).displayed? }76 rescue Selenium::WebDriver::Error::TimeOutError77 # TODO: log this exeption78 # Meta.logger.info("In page ")79 return80 end81 true82 end83 end...
empire_crawler.rb
Source:empire_crawler.rb
...11 schedule_scrape(plan_id, url)12 return13 end14 end15 page_source = nil16 Headless.ly do17 caps = Selenium::WebDriver::Remote::Capabilities.firefox18 caps['acceptInsecureCerts'] = true19 @driver = Selenium::WebDriver.for :firefox, desired_capabilities: caps20 begin21 @driver.navigate.to url22 @wait.until do23 @driver.find_element(css: "div[data-test='results-count-greater-than-one']")24 end25 page_source = @driver.page_source26 self.ssdb.set(url, sanitize_for_ssdb(page_source))27 schedule_scrape(plan_id, url)28 @driver.quit29 rescue Exception => e30 # Make sure we quit the browser even if we run into an exception we didn't anticipate31 @driver.quit32 raise e33 end34 end35 end36 def self.schedule_scrape plan_id, url37 STDOUT.puts("Enqueueing EmpireScraper with [#{plan_id}, #{url}]")38 Resque.push('scraper_empire', :class => 'Jobs::Scrapers::EmpireScraper', :args => [plan_id, url])39 end40 end...
page_source
Using AI Code Generation
1element = driver.find_element(:name, 'q')2elements = driver.find_elements(:tag_name, 'a')3 puts e.attribute('href')4element = driver.find_element(:name, 'q')5element = driver.find_element(:name, 'q')
page_source
Using AI Code Generation
1puts driver.find_element(:id, "hplogo").page_source2puts driver.find_element(:id, "hplogo").attribute("innerHTML")3puts driver.find_element(:id, "hplogo").attribute("outerHTML")4puts driver.find_element(:id, "hplogo").attribute("outerHTML")5puts driver.find_element(:id, "hplogo").attribute("innerHTML")6puts driver.find_element(:id, "hplogo").attribute("outerHTML")
page_source
Using AI Code Generation
1using OpenQA.Selenium;2using OpenQA.Selenium.Firefox;3using System;4{5 {6 static void Main(string[] args)7 {8 IWebDriver driver = new FirefoxDriver();9 driver.Navigate().GoToUrl("http://www.google.com");10 Console.WriteLine(driver.PageSource);11 driver.Quit();12 }13 }14}15import org.openqa.selenium.By;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.firefox.FirefoxDriver;18public class SeleniumWebDriver {19 public static void main(String[] args) {20 WebDriver driver = new FirefoxDriver();21 driver.get("http://www.google.com");22 System.out.println(driver.getPageSource());23 driver.quit();24 }25}26from selenium import webdriver27driver = webdriver.Firefox()28driver.get("http://www.google.com")29driver.quit()30require_once('vendor/autoload.php');31use Facebook\WebDriver\Remote\RemoteWebDriver;32use Facebook\WebDriver\Remote\DesiredCapabilities;33use Facebook\WebDriver\WebDriverBy;34use Facebook\WebDriver\WebDriverExpectedConditions;35use Facebook\WebDriver\WebDriverWait;36$host = 'http://localhost:4444/wd/hub';37$driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());38$driver->get('http://www.google.com');39echo $driver->getPageSource();40$driver->quit();
page_source
Using AI Code Generation
1element = driver.find_element(:name, 'q')2elements = driver.find_elements(:tag_name, 'a')3 puts e.attribute('href')4element = driver.find_element(:name, 'q')5element = driver.find_element(:name, 'q')
page_source
Using AI Code Generation
1puts driver.find_element(:id, "hplogo").page_source2puts driver.find_element(:id, "hplogo").attribute("innerHTML")3puts driver.find_element(:id, "hplogo").attribute("outerHTML")4puts driver.find_element(:id, "hplogo").attribute("outerHTML")5puts driver.find_element(:id, "hplogo").attribute("innerHTML")6puts driver.find_element(:id, "hplogo").attribute("outerHTML")
page_source
Using AI Code Generation
1using OpenQA.Selenium;2using OpenQA.Selenium.Firefox;3using System;4{5 {6 static void Main(string[] args)7 {8 IWebDriver driver = new FirefoxDriver();9 driver.Navigate().GoToUrl("http://www.google.com");10 Console.WriteLine(driver.PageSource);11 driver.Quit();12 }13 }14}15import org.openqa.selenium.By;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.firefox.FirefoxDriver;18public class SeleniumWebDriver {19 public static void main(String[] args) {20 WebDriver driver = new FirefoxDriver();21 driver.get("http://www.google.com");22 System.out.println(driver.getPageSource());23 driver.quit();24 }25}26from selenium import webdriver27driver = webdriver.Firefox()28driver.get("http://www.google.com")29driver.quit()30require_once('vendor/autoload.php');31use Facebook\WebDriver\Remote\RemoteWebDriver;32use Facebook\WebDriver\Remote\DesiredCapabilities;33use Facebook\WebDriver\WebDriverBy;34use Facebook\WebDriver\WebDriverExpectedConditions;35use Facebook\WebDriver\WebDriverWait;36$host = 'http://localhost:4444/wd/hub';37$driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());38$driver->get('http://www.google.com');39echo $driver->getPageSource();40$driver->quit();
page_source
Using AI Code Generation
1element = driver.find_element(:name, 'q')2elements = driver.find_elements(:tag_name, 'a')3 puts e.attribute('href')4element = driver.find_element(:name, 'q')5element = driver.find_element(:name, 'q')
page_source
Using AI Code Generation
1puts driver.find_element(:id, "hplogo").page_source2puts driver.find_element(:id, "hplogo").attribute("innerHTML")3puts driver.find_element(:id, "hplogo").attribute("outerHTML")4puts driver.find_element(:id, "hplogo").attribute("outerHTML")5puts driver.find_element(:id, "hplogo").attribute("innerHTML")6puts driver.find_element(:id, "hplogo").attribute("outerHTML")
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!!