Display results as :

Rechercher Advanced Search

Latest topics
» how to connect DB in selenium webriver
Fri Oct 06, 2017 4:09 pm by anbarasi

» How find any text in browser screen and click on it?
Thu Oct 05, 2017 2:02 pm by sandeepkommineni

» Selenium Webdriver
Tue Oct 03, 2017 1:35 pm by PiyushBiswas

» GRID setup tutorial.
Wed Sep 27, 2017 4:29 pm by johnyapp

» Drag & Drop Between Windows Using Selenium Driver
Wed Sep 27, 2017 2:10 pm by 26rondel

» Check if window is closed / verify input
Sat Sep 23, 2017 10:21 pm by brainstir

» How to work on pages with AJAX in selenium?
Mon Sep 18, 2017 6:08 pm by azharuddin

» pause test until user press a key like F2
Wed Aug 09, 2017 11:10 pm by djnforce

» Selecting the input for auto populating element
Sat Jul 29, 2017 7:53 pm by kdabbara


Accessing dynamic attribute

View previous topic View next topic Go down

Accessing dynamic attribute

Post by terrynweze on Thu Mar 01, 2012 5:34 pm


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

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("state")).getAttribute("data-state").equalsIgnoreCase("open");

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)

name="state" id="state" class="validatable"

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)


Posts : 5
Join date : 2012-03-01

Back to top Go down

Re: Accessing dynamic attribute

Post by terrynweze on 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')");


Posts : 5
Join date : 2012-03-01

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum