[wtr-general] Re: Webdriver : when i have to grab the id using pattern match it fails for firefox
Well i got it working with index : $ie.text_field(:class => "inputbg", :index => 0).set "bhavesh" sleep(5) But still im finding ways. Bhavesh On Dec 9, 3:17 pm, Bhavesh wrote: > Hi, > > I got the solution, i written code like this : > > $ie.div(:class => "cell-inner overflow-hidden", :text => > "bhavtest").click > > And it works. > > But there are some cases where only thing we can get is id which is > dynamic like an text filed: > > z.type="zul.widget.Txbox">. > > Here it is only dynmaic id and not even any text. > > I see two problems : > > 1. How can i enter text in this text field when i just have dynamic id > usng webdriver? > > 2. This particular html is present many times in a page, so to get > the ID, which is dynamic, it is very difficult. Here i cannot use > class as it is same in many text fields. If i club index here then it > is alos risky as many text fileds gets added/removed as applicaiton > developed. > > So is there any way i can identify this textbox? > > Right now i pattern match it with few lines above this code, i mean > right now page is like > > "Name: ", > passwrod:" > > So i pattern match with "Name:" then till this textfield. Grabs the > id and then enter text in it, like : > > if /Name:.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.* > \n.*\n.*\n.*\n.*\n.*\n.* > But in webdriver this pattern match is not usable, then i have a > problem, can you suggest any solution to this? > > Bhavesh > On Dec 9, 2:21 pm, Chuck van der Linden wrote: > > > > > > > > > Lets backup a minute because I think you are going about this in a > > very convoluted way based on something you figured out that works, but > > may in fact be a bit of a kludge. > > > The div being clicked on contains a link, an image, and a span with > > text. > > > First question, when interfacing with the site, how does a HUMAN know > > what to click on? Is it the image being displayed? The text? the > > combination of the two? or either? > > > If it's the text, then why not just select the div that way > > > b.div(:text => 'bhavtest').click > > > If it's the Image, then why not find that using a regex for the src > > of the image, and then use .parent to locate the containing div and > > click it? > > > b.img(:src => /your_regex_here/).parent.click > > > if it needs to be a parameter then replace the constants above with a > > variable, or a regex object created from a variable > > > If it's the combination of the two things (image and text) then you > > might have to be a bit trickier but it should still be possible and a > > bit more straightforward than what you were doing. > > > Using ID's to identify something is great where that is something you > > can predict, but otherwise, if you are using some other means to find > > the thing you want, doing that in order to get the ID and then using > > the ID to interact with the element is really just taking the long way > > around. Instead (unless it's not supported) use the thing you know to > > identify and interact with the element. > > > On Dec 9, 11:02 am, Bhavesh wrote: > > > > Ok, > > > > Here is the line that im matching from source from IE : > > > > > > sel href="javascript:;" z.type="Lcfc">https://vm- > > > bhaveshok2.kazeon.local/admin/images/ > > > green_dot.png"align=absMiddle> > > title=bhavtest>bhavtest > > > > My subroutine code is : > > > > def clickFSlink(fsname="") > > > printClickInfo("clickfslink", fsname) > > > $_ = $ie.html > > > if /.*dot.png.*#{fsname}/ > > > printIDInfo("FS ID", $1) > > > begin > > > $ie.div(:id , $1).click > > > rescue => e > > > rescueHandle(e) > > > end > > > sleep($deepSleep) > > > else > > > puts "FAILED! Could not find DatafsID" > > > return false > > > end > > > end > > > > My script is : > > > > require 'watir-webdriver' > > > require 'Lib/KazeonCommon/BasicMethodLibrary' > > > > class test1< Test::Unit::TestCase > > > > def test_ > > > puts > > > "** > > > " > > > printTestingReportHeader("I18N Regression Testing", "WEB_ADMIN") > > > puts > > > "** > > > " > > > end > > > > def test_0001 > > > returnValue = true > > > $ie.goto($adminLink) > > > sleep(10) > > > #skipSecurity("Continue to this website") > > > kazeonLegalLogin("WEB_ADMIN", "Local", "admin", "kazeon") > > > sleep(5) > > > clickFSlink("bhavtest") ## Here it fails for firefox. > > > end > > > > end > > > > This works well in Ie, but when i use the same code by changing > > > browser to firefox, it fails. > > > > Bhavesh > > > > On Dec 9, 10:42 am, Željko Filipin > > > wrote: > > > > > On Fri, Dec 9, 2011 at 7:06 PM, Bhavesh > > > > wrote: > > > > > Here im matching "bhavtest"
[wtr-general] Re: Webdriver : when i have to grab the id using pattern match it fails for firefox
Hi, I got the solution, i written code like this : $ie.div(:class => "cell-inner overflow-hidden", :text => "bhavtest").click And it works. But there are some cases where only thing we can get is id which is dynamic like an text filed: . Here it is only dynmaic id and not even any text. I see two problems : 1. How can i enter text in this text field when i just have dynamic id usng webdriver? 2. This particular html is present many times in a page, so to get the ID, which is dynamic, it is very difficult. Here i cannot use class as it is same in many text fields. If i club index here then it is alos risky as many text fileds gets added/removed as applicaiton developed. So is there any way i can identify this textbox? Right now i pattern match it with few lines above this code, i mean right now page is like "Name: ", passwrod:" So i pattern match with "Name:" then till this textfield. Grabs the id and then enter text in it, like : if /Name:.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.*\n.* \n.*\n.*\n.*\n.*\n.*\n.* wrote: > Lets backup a minute because I think you are going about this in a > very convoluted way based on something you figured out that works, but > may in fact be a bit of a kludge. > > The div being clicked on contains a link, an image, and a span with > text. > > First question, when interfacing with the site, how does a HUMAN know > what to click on? Is it the image being displayed? The text? the > combination of the two? or either? > > If it's the text, then why not just select the div that way > > b.div(:text => 'bhavtest').click > > If it's the Image, then why not find that using a regex for the src > of the image, and then use .parent to locate the containing div and > click it? > > b.img(:src => /your_regex_here/).parent.click > > if it needs to be a parameter then replace the constants above with a > variable, or a regex object created from a variable > > If it's the combination of the two things (image and text) then you > might have to be a bit trickier but it should still be possible and a > bit more straightforward than what you were doing. > > Using ID's to identify something is great where that is something you > can predict, but otherwise, if you are using some other means to find > the thing you want, doing that in order to get the ID and then using > the ID to interact with the element is really just taking the long way > around. Instead (unless it's not supported) use the thing you know to > identify and interact with the element. > > On Dec 9, 11:02 am, Bhavesh wrote: > > > > > > > > > Ok, > > > Here is the line that im matching from source from IE : > > > > sel href="javascript:;" z.type="Lcfc">https://vm- > > bhaveshok2.kazeon.local/admin/images/ > > green_dot.png"align=absMiddle> > title=bhavtest>bhavtest > > > My subroutine code is : > > > def clickFSlink(fsname="") > > printClickInfo("clickfslink", fsname) > > $_ = $ie.html > > if /.*dot.png.*#{fsname}/ > > printIDInfo("FS ID", $1) > > begin > > $ie.div(:id , $1).click > > rescue => e > > rescueHandle(e) > > end > > sleep($deepSleep) > > else > > puts "FAILED! Could not find DatafsID" > > return false > > end > > end > > > My script is : > > > require 'watir-webdriver' > > require 'Lib/KazeonCommon/BasicMethodLibrary' > > > class test1< Test::Unit::TestCase > > > def test_ > > puts > > "** > > " > > printTestingReportHeader("I18N Regression Testing", "WEB_ADMIN") > > puts > > "** > > " > > end > > > def test_0001 > > returnValue = true > > $ie.goto($adminLink) > > sleep(10) > > #skipSecurity("Continue to this website") > > kazeonLegalLogin("WEB_ADMIN", "Local", "admin", "kazeon") > > sleep(5) > > clickFSlink("bhavtest") ## Here it fails for firefox. > > end > > > end > > > This works well in Ie, but when i use the same code by changing > > browser to firefox, it fails. > > > Bhavesh > > > On Dec 9, 10:42 am, Željko Filipin > > wrote: > > > > On Fri, Dec 9, 2011 at 7:06 PM, Bhavesh wrote: > > > > Here im matching "bhavtest" which is actually parameter #{fsname}. > > > > By matching this line, im collecting id div "z_bp_ud!cave" > > > > Then trying to click on that div in UI -- > > > > browser.div(:id , $1).click > > > > I am completely confused. Could you please send only the tag that > > > interests > > > you and your watir code? > > > > Željko -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] Re: Webdriver : when i have to grab the id using pattern match it fails for firefox
Lets backup a minute because I think you are going about this in a very convoluted way based on something you figured out that works, but may in fact be a bit of a kludge. The div being clicked on contains a link, an image, and a span with text. First question, when interfacing with the site, how does a HUMAN know what to click on? Is it the image being displayed? The text? the combination of the two? or either? If it's the text, then why not just select the div that way b.div(:text => 'bhavtest').click If it's the Image, then why not find that using a regex for the src of the image, and then use .parent to locate the containing div and click it? b.img(:src => /your_regex_here/).parent.click if it needs to be a parameter then replace the constants above with a variable, or a regex object created from a variable If it's the combination of the two things (image and text) then you might have to be a bit trickier but it should still be possible and a bit more straightforward than what you were doing. Using ID's to identify something is great where that is something you can predict, but otherwise, if you are using some other means to find the thing you want, doing that in order to get the ID and then using the ID to interact with the element is really just taking the long way around. Instead (unless it's not supported) use the thing you know to identify and interact with the element. On Dec 9, 11:02 am, Bhavesh wrote: > Ok, > > Here is the line that im matching from source from IE : > > sel href="javascript:;" z.type="Lcfc">https://vm- > bhaveshok2.kazeon.local/admin/images/ > green_dot.png"align=absMiddle> title=bhavtest>bhavtest > > My subroutine code is : > > def clickFSlink(fsname="") > printClickInfo("clickfslink", fsname) > $_ = $ie.html > if /.*dot.png.*#{fsname}/ > printIDInfo("FS ID", $1) > begin > $ie.div(:id , $1).click > rescue => e > rescueHandle(e) > end > sleep($deepSleep) > else > puts "FAILED! Could not find DatafsID" > return false > end > end > > My script is : > > require 'watir-webdriver' > require 'Lib/KazeonCommon/BasicMethodLibrary' > > class test1< Test::Unit::TestCase > > def test_ > puts > "**" > printTestingReportHeader("I18N Regression Testing", "WEB_ADMIN") > puts > "**" > end > > def test_0001 > returnValue = true > $ie.goto($adminLink) > sleep(10) > #skipSecurity("Continue to this website") > kazeonLegalLogin("WEB_ADMIN", "Local", "admin", "kazeon") > sleep(5) > clickFSlink("bhavtest") ## Here it fails for firefox. > end > > end > > This works well in Ie, but when i use the same code by changing > browser to firefox, it fails. > > Bhavesh > > On Dec 9, 10:42 am, Željko Filipin > wrote: > > > > > > > > > On Fri, Dec 9, 2011 at 7:06 PM, Bhavesh wrote: > > > Here im matching "bhavtest" which is actually parameter #{fsname}. > > > By matching this line, im collecting id div "z_bp_ud!cave" > > > Then trying to click on that div in UI -- > > > browser.div(:id , $1).click > > > I am completely confused. Could you please send only the tag that interests > > you and your watir code? > > > Željko -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] Re: Button click in IE8 using watir web-driver.
On Dec 9, 8:06 am, Prajakta Jadhav wrote: > Hello, > > I am just following this script onhttp://watirwebdriver.com/: > require 'watir-webdriver' > b = Watir::Browser.new > b.goto 'bit.ly/watir-webdriver-demo' > b.text_field(:id => 'entry_0').set 'your name' > b.select_list(:id => 'entry_1').select 'Ruby' > b.select_list(:id => 'entry_1').selected? 'Ruby' > #~ b.div(:class => 'ss-form-entry').button.click -- > This line gives 'element not found' error, so changed this to: > b.button(:name => 'submit').click > b.text.include? 'Thank you' > > The "b.button(:name => 'submit').click" does not work in IE8. I > tried .focus and .flash and they work, but .click does not. > It works correctly on chrome and firefox. > > I have also tried: > b.button(:name => 'submit').fire_event "mouseover" > b.button(:name => 'submit').fire_event "click" > which again does not work. > This is strange, and seems to get stranger as I dig at it. Let me allow you to watch over my shoulder while I do a big of sleuthing here I'm getting a similar error with the initial line of failing code using IE9, I also get the SAME error in FF8 AND Chrome So it's NOT browser specific. b.div(:class => 'ss-form-entry').button.click > Watir::Exception::UnknownObjectException: unable to locate element, using {:tag_name=>"button"} from C:/Rubies/Ruby192/lib/ruby/gems/1.9.1/gems/watir- webdriver-0.3.8/lib/watir-webdriver/elements/element.rb:253:in `assert_exists' from C:/Rubies/Ruby192/lib/ruby/gems/1.9.1/gems/watir- webdriver-0.3.8/lib/watir-webdriver/elements/element.rb:65:in `click' The container div shows up clear as day in the IE and Chrome developer tools, and a check for .exist? on it returns true. while b.div(:class => 'ss-form-entry').button.exist? #returns false b.div(:class => 'ss-form-entry').button(:name => 'submit').exist? #returns false but b.button(:name => 'submit').exist? #returns true Digging my way up the DOM hierarchy one container higher b.div(:class => "ss-item ss-navigate").button.exist? "returns true Um? WTH this really seems strange, why is selecting it from the parent div container failing, but from the parent of that container works? SO, is it really in that div? lets see who it thinks it's parent is > puts b.button(:name => 'submit').parent.attribute_value('class') #returns: > ss-form-entry ok um how about selecting it via it's own parent (a bit circular but still an amusing test b.button(:name => 'submit').parent.button.exist? #returns true What about via the grandparent using the same criteria for the parent (looking for class etc) b.button(:name => 'submit').parent.parent.div(:class, 'ss-form- entry').button.exist? #returns true very curious.. OK brain flash occurs. doing that restricted the search for our container div to a much smaller section of the entire DOM.. so perhaps, just.MAYBE that div is not unique? Lets find out b.divs(:class, 'ss-form-entry').size #returns 5BINGO Mystery solved. (was that sample code? we'll want to go revise it I expect) BTW: from IE9 I can click the button just fine using either b.div(:class => "ss-item ss-navigate").button.click or b.div.button(:name => 'submit').click, but strangely enough (from IRB) I sometimes have to repeat the click method a second time to actually have the object get clicked. That's a behavior I've seen elsewhere using .click methods from IRB and I've no idea what causes that to be intermittent like that. it tends to always work from scripts so I have to think it's some kind of window focus switching thing going on, potentially related to UI performance since I'm using a windows VM running under virtualbox on a macbook.. point being, if you are doing stuff from IRB and a click fails, try it a second time -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] Re: Webdriver : when i have to grab the id using pattern match it fails for firefox
Ok, Here is the line that im matching from source from IE : https://vm- bhaveshok2.kazeon.local/admin/images/ green_dot.png"align=absMiddle>bhavtest My subroutine code is : def clickFSlink(fsname="") printClickInfo("clickfslink", fsname) $_ = $ie.html if /.*dot.png.*#{fsname}/ printIDInfo("FS ID", $1) begin $ie.div(:id , $1).click rescue => e rescueHandle(e) end sleep($deepSleep) else puts "FAILED! Could not find DatafsID" return false end end My script is : require 'watir-webdriver' require 'Lib/KazeonCommon/BasicMethodLibrary' class test1< Test::Unit::TestCase def test_ puts "**" printTestingReportHeader("I18N Regression Testing", "WEB_ADMIN") puts "**" end def test_0001 returnValue = true $ie.goto($adminLink) sleep(10) #skipSecurity("Continue to this website") kazeonLegalLogin("WEB_ADMIN", "Local", "admin", "kazeon") sleep(5) clickFSlink("bhavtest") ## Here it fails for firefox. end end This works well in Ie, but when i use the same code by changing browser to firefox, it fails. Bhavesh On Dec 9, 10:42 am, Željko Filipin wrote: > On Fri, Dec 9, 2011 at 7:06 PM, Bhavesh wrote: > > Here im matching "bhavtest" which is actually parameter #{fsname}. > > By matching this line, im collecting id div "z_bp_ud!cave" > > Then trying to click on that div in UI -- > > browser.div(:id , $1).click > > I am completely confused. Could you please send only the tag that interests > you and your watir code? > > Željko -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
Re: [wtr-general] Re: Webdriver : when i have to grab the id using pattern match it fails for firefox
On Fri, Dec 9, 2011 at 7:06 PM, Bhavesh wrote: > Here im matching "bhavtest" which is actually parameter #{fsname}. > By matching this line, im collecting id div "z_bp_ud!cave" > Then trying to click on that div in UI -- > browser.div(:id , $1).click I am completely confused. Could you please send only the tag that interests you and your watir code? Željko -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] Re: Webdriver : when i have to grab the id using pattern match it fails for firefox
Hi, Here is the source that get generated in IE: https://vm- bhaveshok2.kazeon.local/admin/images/green_dot.png" align=absMiddle>bhavtest https://vm-bhaveshok2.kazeon.local/admin/images/datafs.png"; border=0 z.type="zul.widget.Img"> datafs (nfs) testkaz ntap34 /vol/data/ bhavnfsdata2(tcp,rw) 0 online ## Here im matching "bhavtest" which is actually parameter #{fsname}. By matching this line, im collecting id div "z_bp_ud!cave" Then trying to click on that div in UI -- browser.div(:id , $1).click Now this source is generated differentily in Firefox, so this pattern match failed, and im not able to use it. Im using watir from last 2 years but always as a unit test framework. I switched to Webdriver just now as a requirement and therefore i need my previous code to be align to webdriver so that i can execute my script on all browsers. Can you help me out here? Is there any way i can port all my scripts to webdriver? Bhavesh On Dec 9, 3:48 am, Željko Filipin wrote: > On Fri, Dec 9, 2011 at 12:56 AM, Bhavesh wrote: > > so to collect the id's, i go to source of that page and grab the id > > like : > > $_ = $ie.html > > if /.*dot.png.*#{fsname}/ > > printIDInfo("FS ID", $1) > > Why aren't you using watir api? > > Something like > > browser.divs(how, what).collect {|div| div.id} > > If you provide sample html, we could tell more. > > If it is for speed, there are a few html parsers for ruby: > > https://www.ruby-toolbox.com/categories/html_parsing > > Željko > -- > watir.com/book - author -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] Button click in IE8 using watir web-driver.
Hello, I am just following this script on http://watirwebdriver.com/: require 'watir-webdriver' b = Watir::Browser.new b.goto 'bit.ly/watir-webdriver-demo' b.text_field(:id => 'entry_0').set 'your name' b.select_list(:id => 'entry_1').select 'Ruby' b.select_list(:id => 'entry_1').selected? 'Ruby' #~ b.div(:class => 'ss-form-entry').button.click -- This line gives 'element not found' error, so changed this to: b.button(:name => 'submit').click b.text.include? 'Thank you' The "b.button(:name => 'submit').click" does not work in IE8. I tried .focus and .flash and they work, but .click does not. It works correctly on chrome and firefox. I have also tried: b.button(:name => 'submit').fire_event "mouseover" b.button(:name => 'submit').fire_event "click" which again does not work. My protected mode setting is ON in all places and the pop-up blocker is OFF. I do not have a Google Toolbar that might block anything. Could somebody please help me find the problem here? Could you try this script on your IE8 browser and see if it works for you? Thanks, Prajakta -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
Re: [wtr-general] How do i drag Element to the Page?
On Fri, Dec 9, 2011 at 1:15 PM, ash wrote: > I am facing problem on dragging element to the page. https://www.google.com/search?q=watir+webdriver+drag Željko -- watir.com/book - author -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] How do i drag Element to the Page?
Hi, I am facing problem on dragging element to the page. Any help would be appreciated. Thanks -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
Re: [wtr-general] Webdriver : when i have to grab the id using pattern match it fails for firefox
On Fri, Dec 9, 2011 at 12:56 AM, Bhavesh wrote: > so to collect the id's, i go to source of that page and grab the id > like : > $_ = $ie.html > if /.*dot.png.*#{fsname}/ > printIDInfo("FS ID", $1) Why aren't you using watir api? Something like browser.divs(how, what).collect {|div| div.id} If you provide sample html, we could tell more. If it is for speed, there are a few html parsers for ruby: https://www.ruby-toolbox.com/categories/html_parsing Željko -- watir.com/book - author -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com