Actually in watir you can not open ulr's in new tab. If you want to open 2 or more web sites via watir in same browser but in new tab, you can not do this. I search on internet but i dint found any solution on this issue,...! suddenly i got some new ideas in my mind.
First open browser via ruby using command i.e
puts `Start /Max iexplore http://google.com`
puts `Start /Max iexplore http://www.port43whois.com/`
puts `Start /Max firefox http://yahoo.com`
OR
require 'win32ole'
ie = WIN32OLE.new('InternetExplorer.Application')
ie.visible = true
ie.navigate("http://google.com")
sleep(1) until ie.ReadyState == 4
ie.navigate("http://www.port43whois.com/",2048)
sleep(1) until ie.ReadyState == 4
ie.navigate("http://yahoo.com",2048)
sleep(1) until ie.ReadyState == 4
it will open all these sites in diff.tabs , then you can use below mentioned method...
A) ie = Watir::IE.attach(:url, 'http://google.com')
ie2 = Watir::IE.attach(:url, 'http://www.port43whois.com/')
ie3 = Watir::IE.attach(:url, 'http://yahoo.com')
B) ie = Watir::IE.find(:url, 'http://google.com')
ie2 = Watir::IE.find(:url, 'http://www.port43whois.com/')
ie3 = Watir::IE.find(:url, 'http://yahoo.com')
Friday, October 29, 2010
Open Internet Explorer at the specified URL
$browser = Watir::IE.start("http://google.com")
$browser = Watir::IE.start "http://google.com"
Attach to an existing browser, raising an exception if it isn't found
$browser = Watir::IE.attach(:url, "http://www.google.com")
$browser = Watir::IE.attach(:title, "Google")
Attach to an existing browser, returning nil if it isn't found
$browser = Watir::IE.find(:title, "Google")
$browser = Watir::IE.find(:url, "http://www.google.com")
$browser = Watir::IE.start "http://google.com"
Attach to an existing browser, raising an exception if it isn't found
$browser = Watir::IE.attach(:url, "http://www.google.com")
$browser = Watir::IE.attach(:title, "Google")
Attach to an existing browser, returning nil if it isn't found
$browser = Watir::IE.find(:title, "Google")
$browser = Watir::IE.find(:url, "http://www.google.com")
Thursday, October 28, 2010
Open Firefox
require 'watir'
Watir::Browser.default = "firefox"
b = Watir::Browser.start("http://www.google.com")
b.text_field(:name, "q").set "watir"
b.button(:name, "btnG").click
b.link(:href, "http://watir.com/").click
puts b.text.include?("Why Watir?")
Watir::Browser.default = "firefox"
b = Watir::Browser.start("http://www.google.com")
b.text_field(:name, "q").set "watir"
b.button(:name, "btnG").click
b.link(:href, "http://watir.com/").click
puts b.text.include?("Why Watir?")
Wednesday, October 27, 2010
New Browser Windows
ie1 = Watir::IE.attach(:url, 'http://mytestsite')
ie2 = Watir::IE.attach(:title, 'Test New Window')
The best benefit of Watir::IE.attach maybe, we don't need to initialize our IE window once the windows exists.
We just need locate the tab, then practice on the page.
We can locate any tab we want.
#Get the title and url of the tab existent.
Watir::IE.each do |tab|
puts tab.title
puts tab.url
end
For blank page, we may locate it use:
ie6 = Watir::IE.attach(:title, //)
ie6.goto("test site")
or
ie7=Watir::IE.attach(:url,/about:blank/)
ie7.goto("test site")
ie2 = Watir::IE.attach(:title, 'Test New Window')
The best benefit of Watir::IE.attach maybe, we don't need to initialize our IE window once the windows exists.
We just need locate the tab, then practice on the page.
We can locate any tab we want.
#Get the title and url of the tab existent.
Watir::IE.each do |tab|
puts tab.title
puts tab.url
end
For blank page, we may locate it use:
ie6 = Watir::IE.attach(:title, //)
ie6.goto("test site")
or
ie7=Watir::IE.attach(:url,/about:blank/)
ie7.goto("test site")
Wednesday, October 6, 2010
dog class
class Dog
def setname(aname)
@myname=aname
end
def getname
puts "#{@myname}is a big dog"
end
def talk
return 'bho bho bho'
end
end
print 'Enter dog name: '
dd=gets
mydog=Dog.new
mydog.setname(dd)
puts(mydog.getname)
puts(mydog.talk)
print 'Enter dog name: '
dd=gets
mdog=Dog.new
mdog.setname(dd)
puts(mdog.getname)
puts(mdog.talk)
def setname(aname)
@myname=aname
end
def getname
puts "#{@myname}is a big dog"
end
def talk
return 'bho bho bho'
end
end
print 'Enter dog name: '
dd=gets
mydog=Dog.new
mydog.setname(dd)
puts(mydog.getname)
puts(mydog.talk)
print 'Enter dog name: '
dd=gets
mdog=Dog.new
mdog.setname(dd)
puts(mdog.getname)
puts(mdog.talk)
IE test
require 'win32ole'
ie=WIN32OLE.new('InternetExplorer.Application')
ie.Visible=true
ie.Navigate('http://google.com/')
sleep(1) until ie.ReadyState==4
ie.text_field(:name, "q").set("Vijay Ramane")
ie.button(:name, "btnG").click
#ie.Quit
ie=WIN32OLE.new('InternetExplorer.Application')
ie.Visible=true
ie.Navigate('http://google.com/')
sleep(1) until ie.ReadyState==4
ie.text_field(:name, "q").set("Vijay Ramane")
ie.button(:name, "btnG").click
#ie.Quit
interesting
w=%w{hi hello how he she you they me}
#w=["hi", "hello", "ehich", "he", "she"]
puts "Enter ur name "
name=gets
i=0
while i<7
puts "#{i}: "+w[i]+" #{name}"
i=i.to_i+1
# puts i
end
#w=["hi", "hello", "ehich", "he", "she"]
puts "Enter ur name "
name=gets
i=0
while i<7
puts "#{i}: "+w[i]+" #{name}"
i=i.to_i+1
# puts i
end
open IE without watir
require 'win32ole'
ie1 = WIN32OLE.new('InternetExplorer.Application')
ie2 = WIN32OLE.new('InternetExplorer.Application')
ie1.visible = true
ie2.visible = true
ie1.navigate('http://www.google.com')
sleep(1) until ie1.ReadyState == 4
ie2.navigate('http://www.yahoo.com')
sleep(1) until ie1.ReadyState == 4
ie1.Document.All.q.Value = 'Vijay Ramane'
ie1.Document.All.btnG.click
sleep(1) until ie1.ReadyState == 4
ie1 = WIN32OLE.new('InternetExplorer.Application')
ie2 = WIN32OLE.new('InternetExplorer.Application')
ie1.visible = true
ie2.visible = true
ie1.navigate('http://www.google.com')
sleep(1) until ie1.ReadyState == 4
ie2.navigate('http://www.yahoo.com')
sleep(1) until ie1.ReadyState == 4
ie1.Document.All.q.Value = 'Vijay Ramane'
ie1.Document.All.btnG.click
sleep(1) until ie1.ReadyState == 4
check whois changed or not
require 'watir'
domain=%w[<>]
i=0
a=[]
b=[]
browser = Watir::IE.start "http://www.port43whois.com/index.php"
until i==domain.length
browser.text_field(:name, "query").set(domain[i])
browser.button(:value,"Whois").click
if browser.text.include? ()
a<
else
b<
end
i+=1
end
puts "Whois changed"
puts a
puts ""
puts ""
puts "Whois not changed"
puts b
domain=%w[<>]
i=0
a=[]
b=[]
browser = Watir::IE.start "http://www.port43whois.com/index.php"
until i==domain.length
browser.text_field(:name, "query").set(domain[i])
browser.button(:value,"Whois").click
if browser.text.include? (
a<
else
b<
end
i+=1
end
puts "Whois changed"
puts a
puts ""
puts ""
puts "Whois not changed"
puts b
RFA
require 'watir'
domain=%w[vijay.com yahoo.com google.com]
i=0
until i==domain.length
ie=Watir::IE.attach(:title, "List Rfas")
ie.text_field(:name, "description").set(domain[i])
ie.select_list(:name, "rfaType").set("Transfer In")
ie.button(:value, /Search/).click
if ie.text.include? "No Rfas Found"
puts domain[i]
else
ie.checkbox(:name, "orderid_desc").set
end
i+=1
end
domain=%w[vijay.com yahoo.com google.com]
i=0
until i==domain.length
ie=Watir::IE.attach(:title, "List Rfas")
ie.text_field(:name, "description").set(domain[i])
ie.select_list(:name, "rfaType").set("Transfer In")
ie.button(:value, /Search/).click
if ie.text.include? "No Rfas Found"
puts domain[i]
else
ie.checkbox(:name, "orderid_desc").set
end
i+=1
end
define method
print 'enter no '
n1=gets
print 'enter no '
n2=gets
def vk (n1,n2)
puts n1.to_i+n2.to_i
end
puts vk(10,12)
puts vk(n1,n2)
n1=gets
print 'enter no '
n2=gets
def vk (n1,n2)
puts n1.to_i+n2.to_i
end
puts vk(10,12)
puts vk(n1,n2)
open google & yahoo
require 'watir'
#require 'watir-webdriver'
#require 'firewatir'
vj1=Watir::IE.attach(:title, "Google")
vj2=Watir::IE.attach(:title, "Yahoo! India")
vj1.text_field(:name, "q").set "vijay ramane"
vj2.text_field(:name, "p").set "vijay ramane"
#require 'watir-webdriver'
#require 'firewatir'
vj1=Watir::IE.attach(:title, "Google")
vj2=Watir::IE.attach(:title, "Yahoo! India")
vj1.text_field(:name, "q").set "vijay ramane"
vj2.text_field(:name, "p").set "vijay ramane"
class sample
class Person
attr_accessor :name, :age, :gender
end
class Vijay < Person
end
class Kishor end
class Jayesh end
vijay=Vijay.new
vijay.name="vijay ramane"
vijay.age=26
vijay.gender="male"
kishor=Kishor.new
kishor.name="kishor mali"
kishor.age=14*2
kishor.gender="male"
jayesh=Jayesh.new
jayesh.name="jayesh pednekar"
jayesh.age=25
jayesh.gender="male"
puts
puts vijay.name, vijay.age, vijay.gender
puts
puts kishor.name, kishor.age, kishor.gender
puts
puts jayesh.name, jayesh.age, jayesh.gender
puts
vijay.name
attr_accessor :name, :age, :gender
end
class Vijay < Person
end
class Kishor
class Jayesh
vijay=Vijay.new
vijay.name="vijay ramane"
vijay.age=26
vijay.gender="male"
kishor=Kishor.new
kishor.name="kishor mali"
kishor.age=14*2
kishor.gender="male"
jayesh=Jayesh.new
jayesh.name="jayesh pednekar"
jayesh.age=25
jayesh.gender="male"
puts
puts vijay.name, vijay.age, vijay.gender
puts
puts kishor.name, kishor.age, kishor.gender
puts
puts jayesh.name, jayesh.age, jayesh.gender
puts
vijay.name
uncommon elements
a=%w[my tina name is vijay ramane]
b=%w[what is my name reema]
puts (a-b)+(b-a)
b=%w[what is my name reema]
puts (a-b)+(b-a)
script
l="hello"
$g="goodbye"
def m1
l=10
puts(l)
puts($g)
end
def m2
l=500
$g="vijay"
puts(l)
puts($g)
end
puts m1
puts m2
puts l
$g="goodbye"
def m1
l=10
puts(l)
puts($g)
end
def m2
l=500
$g="vijay"
puts(l)
puts($g)
end
puts m1
puts m2
puts l
open notepad via ruby script
i=0
until i.to_i==45
puts `notepad.exe`
puts "Enter right number"
i=gets
end
until i.to_i==45
puts `notepad.exe`
puts "Enter right number"
i=gets
end
Subscribe to:
Comments (Atom)