new method WebElement.setAttribute

1,295 views
Skip to first unread message

techi

unread,
Jul 8, 2010, 5:15:24 AM7/8/10
to webdriver
Hi ,

When can we expect the next release of WebDriver and having a method
like
WebElement setAttribute(attribute, newValue) ;

Having such method could solve a lot of problems when using
JavascriptExecutor.
WebDriver is a good tool, however it lacks of many features , so the
easiest and quickest way of finding out a temporary solution is mixing
Javascript through JavascriptExecutor and webdriver API.

For instance I have a website that contains a tree of many elements,
after finding a certain WebElement using many combinations of
el1.findElement. ... findElement etc.. I get a reference for
WebElement ,i need to perform a specific operation on that element
( right click, or invoke a javascript function on that element,
developers created some API for accessing and manipulating DOM
elements)

How could I do it ? The found element does not contain id attribute. I
think what I could do is to setAttribute for that element and then
using JavaScript perform some operations on it .


e.g html code
we have many "painting-area" in website, developers defined API to
manipulate with them

<script type="text/javascript">
/** code of website ,HTML + Javascript ***/
<
document.drawCirlce = function( id ) {
el = document.getElementById(id)
// code drawing circle on area
}
document.drawSquare = function ( id ) {
el = document.getElementById(id)
// code drawing square on area
}
</script>

<div class="painting-area" /div>

/** WebDriver test code *****/

//What i am saying is

WebElement area = driver.findElement( ... ) ; // it finds element
somehow
area.setAttribute("id", "uniqueID32423") ; // sets unique id
attribute

//invoking accessible API on website
((JavascriptExecutor)
driver).executeScript("document.drawSquare("uniqueID32423") )

//cleaning, removing ID attribute from web element
area.setAttribute("id", null) ;



Thanks,

Pawel

hoang.tuan.su

unread,
Jul 15, 2010, 1:58:54 PM7/15/10
to webdriver
Hello,

I have the same ... wish like you. But I have a workaround for it.
Here's my code, hope that it's clear for you:

String script = "document.getElementsByName('sitetitle')
[0].setAttribute('maxlength',
1000);document.getElementsByName('sitetitle')
[0].value='123456789123456789123456789123456789123456789123456789123456789';";
(driver as IJavaScriptExecutor).ExecuteScript(script);

In this case, the "sitetitle" element with the maxlength attribute
doesn't allow me to input the data which length is over 50. So I use
script to overcome it.

HTS

On Jul 8, 4:15 pm, techi <ppad...@gmail.com> wrote:
> Hi ,
>
> When can we expect the next release of WebDriver and having a method
> like
> WebElementsetAttribute(attribute, newValue) ;
>
> Having such method could solve a lot of problems when using
> JavascriptExecutor.
> WebDriver is a good tool, however it lacks of many features , so the
> easiest and quickest way of finding out a temporary solution is mixing
> Javascript through JavascriptExecutor and webdriver API.
>
> For instance I have a website that contains  a tree of many elements,
> after finding  a certain WebElement using many combinations of
> el1.findElement. ... findElement etc.. I get a reference for
> WebElement ,i need to perform a specific operation on that element
> ( right click, or invoke a javascript function on that element,
> developers created some API for accessing and manipulating DOM
> elements)
>
> How could I do it ? The found element does not contain id attribute. I
> think what I could do is tosetAttributefor that element and then
Reply all
Reply to author
Forward
0 new messages