Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
terrynweze
Posts : 5
Join date : 2012-03-01

Accessing dynamic attribute Empty Accessing dynamic attribute

Thu Mar 01, 2012 5:34 pm
Hello

I am struggling to get the value of an elements attribute that is generated dynamically

the
attribute data-state seen below is dynamically generated and changes
between closed & open depending as to whether or not the select
object is expanded or collapsed.

<1select id="state" class="validatable" data-vrule-required="true" data-vmessage-prefix="requestQuoteFormTemplate.state" name="state" data-state="closed">

The code i am using to access the attribute is as follows:

public boolean isStateDropDownMenuExpanded() {
return getElementBy(By.id("state")).getAttribute("data-state").equalsIgnoreCase("open");
}

I
get a null pointer exception as the attribute data-state is not found.
When i look at the source code for the page i can see that the attribute
is not seen within the source (see extracted source code below)

<1select
name="state" id="state" class="validatable"
data-vmessage-prefix="requestQuoteFormTemplate.state"
data-vrule-required="true">

any help with this problem would be greatly appreciated.

Note: i have added the number 1 within the select elements above as without it an actual select object is displayed on the page within this forum.


Last edited by terrynweze on Thu Mar 01, 2012 5:38 pm; edited 1 time in total (Reason for editing : the code i was using actually made select objects rather than display the text)
avatar
terrynweze
Posts : 5
Join date : 2012-03-01

Accessing dynamic attribute Empty Re: Accessing dynamic attribute

Mon Mar 05, 2012 7:41 pm
Hello All,

Managed to solve this issue myself and feel a little stupid for not seeing the solution straight away.

I used some javasecript to get the value of the attribute and passed it back into the application

JavascriptExecutor exec = (JavascriptExecutor) webDriver;

String elementState = (String) exec.executeScript("return document.getElementById('state').getAttribute('data-state')");
Back to top
Permissions in this forum:
You cannot reply to topics in this forum