from webdriver backed to webdriver

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

from webdriver backed to webdriver

zlos7ar
Hi guys I am changing my tests from webdriver backed to webdriver as tarunkumar suggested to me in a different post. Can anyone give me some links where I can read about it and learn all the commands.
For example I don't know how to change this :

                selenium.fireEvent("//div[text()='mehr']", "click");

or this:

                selenium.type("name=title", "idea testing");
                selenium.fireEvent("name=title", "blur");

it will be great if you can help me because selenium.fireEvent appears to not work in IE thanks.
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

softwaretestingforum
Administrator
Hi,

I would first suggest you to use WebDriver click method, if it does not work then you could try executing js using JavaScriptExecutor class.

You may also find this post interesting on migration from Selenium to WebDriver -

http://manual-and-automated-testing.1070.n6.nabble.com/Migrating-from-Selenium-RC-to-Webdriver-tp4683930p4683930.html;cid=1334310246211-185 
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
Thanks again for the help but could you give me an example of how to use the JavaScriptExecutor ?
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

softwaretestingforum
Administrator
hmm I assume that WebDriver click does not work in your case.
You can use JavaScriptExecutor as -

((JavaScriptExecutor)driver).executeScript("document.getElementById('element ID').click()")

Here - "document.getElementById('element ID').click()" is DOM expression and you would have to modify it to fit in your element locator
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
Good morning !

when I try this eclipse says that the method executeScript(String) is undefined for the type JavaScriptExecutor are you sure the syntax is correct ?
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

softwaretestingforum
Administrator
Very good morning,

I need to see the html source of locator to guide you precisely. Can you post that? Keep the html source short and pointed to locator you are trying to access.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
<div class="infobox" cfiid="7">
   <div class="headline">Akueller Ideenaufruf</div>
   <div class="stats">
   <div class="switcher">
   <div class="separator" style="width: 152px"/>
   <div class="title">Tolle Rezepte Tolle Rezepte Tolle Rezepte Tolle Rezepte Tolle Rez…</div>
   <div class="description"/>
   <div class="hyvebutton_small buttonleft">mehr</div>
   <div class="hyvebutton_submitbutton buttonright">Idee einreichen</div> //I want to fire click event on this div
</div>


and this is the xpath : //*[@id='content-container']/div[1]/div[9]/div[8]
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

softwaretestingforum
Administrator
Can you first try this in WebDriver -

driver.findElement(By.xPath("//div[contains(text(), 'Idee einreichen ')]")).click()

Resort to js execution only when normal operations of click etc don't work.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
ok this works i was trying to do it like this (without contains() ):
driver.findElement(By.xpath("//div[text()='Idee einreichen']")).click();

maybe thats why it did not work (by the way its not xPath its xpath ) :)

but I still have the problem with the blur effect which I need after every input :

selenium.type("name=title", "idea testing");
selenium.fireEvent("name=title", "blur");

so I still need to know how to execute javascript
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
actually if i have only

driver.findElement(By.xpath("//div[text()='Idee einreichen']")).click();

it does not work and if i have only

driver.findElement(By.xpath("//div[contains(text(), 'Idee einreichen')]")).click();

it still does not work but when i have both it works !? thats strange

driver.findElement(By.xpath("//div[text()='Idee einreichen']")).click();
driver.findElement(By.xpath("//div[contains(text(), 'Idee einreichen')]")).click();
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

softwaretestingforum
Administrator
Since I am not typing in editor hence you can ignore xpath - xPath kinf of typo :)

I am not very sure why combination of both -

driver.findElement(By.xpath("//div[text()='Idee einreichen']")).click();
driver.findElement(By.xpath("//div[contains(text(), 'Idee einreichen')]")).click();

works. You can try following to use blur with js execution -

((JavascriptExecutor)driver).executeScript("document.getElementsByClassName('hyvebutton_submitbutton buttonright')[0].blur")

here I used class name of your div element.
You could try this, but beware that getElementsByClassName is not supported by IE8 and prior. But I am sure you would be able to formulate other dom expression also.

~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
I think before I had both the normal click and the fire event click I thought that it works because of the fire event click but i guess it just needed 2 clicks for some reason i don't know why too. About the xPath i said it because if someone else read this post he will face that problem ;)

anyway the blur effect works thanks :)
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
and ofc it does not work in IE.....

                driver.findElement(By.name("title")).clear();
                driver.findElement(By.name("title")).sendKeys("idea testing");
                ((JavascriptExecutor)driver).executeScript("document.getElementsByName('title')[0].blur");

those 3 lines seems to be doing nothing in IE
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

softwaretestingforum
Administrator
Which version of IE and Selenium-server jar are you working with? Is there any way for me to access application?
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
IE9 and selenium server standalone 2.21.0 I am not sure if you can access it but if you give me skype or email i can send you more details and you can try
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

softwaretestingforum
Administrator
hmm It should work in IE 9, IE 9 is like other standards browsers. You could mail any sensitive detail to tkumarb@gmail.com

b/w I hope you don't use WebDriver as

driver.findElement(Blah Blah Blah)

as it would clutter your test cases. You may like to have a look at - http://www.seleniumtests.com/2012/01/selenium-2-methods-are-no-more-weird.html
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
yep thats exactly how i am using it but why should that be a problem ? btw I sent you an email
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

softwaretestingforum
Administrator
I noticed from your past post that "title"  is class name and not html name, that is -

   <div class="title">Tolle Rezepte Tolle Rezepte Tolle Rezepte Tolle Rezepte Tolle Rez…</div>

While you used it as -
   
    ((JavascriptExecutor)driver).executeScript("document.getElementsByName('title')[0].blur");

Though it should be -

    ((JavascriptExecutor)driver).executeScript("document.getElementsByClassName('title')[0].blur");

and so as -

        driver.findElement(By.name("title")).clear();
        driver.findElement(By.name("title")).sendKeys("idea testing");

should be -

        driver.findElement(By.className("title")).clear();
        driver.findElement(By.className("title")).sendKeys("idea testing");

can you try this?
As far as I know getElementsByClassName is supported in IE 9 so it should work


~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

zlos7ar
I don't think that is the problem this is the html :

<input class="text" type="text" placeholder="Enter Idea title" value="" name="title" style="font-family: Arial;" autosave="true"/>

and thats what i am trying in the webdriver:

driver.findElement(By.name("title")).clear();
driver.findElement(By.name("title")).sendKeys("idea testing");
((JavascriptExecutor)driver).executeScript("document.getElementsByName('text')[0].blur");

and i also cannot use the class name because i have the same name on several elements. I will also look for a solution in google later today or tomorrow and will let you know if i find anything
Reply | Threaded
Open this post in threaded view
|

Re: from webdriver backed to webdriver

softwaretestingforum
Administrator
This post was updated on .
Got it.
So I understand that you don't encounter any error but nothing happens in IE, right?

One stupid question,
Can you try if you are able to carry out clear, sendKeys operations on other input elements in IE 9?
~ seleniumtests.com
12