Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Geting issues in identifying the elsements in webdriver
Fri Feb 17, 2017 4:41 pm by janbaskt

» WebDriver - why not to use a singlton for it?
Fri Feb 17, 2017 4:40 pm by janbaskt

» WebDriver session when using testng annotation to invoke driver instance
Fri Feb 17, 2017 4:39 pm by janbaskt

» Selenium fails to launch Chrome
Fri Feb 17, 2017 4:39 pm by janbaskt

» why do i get this error
Fri Feb 17, 2017 4:38 pm by janbaskt

» Selenium Tutorial
Thu Feb 16, 2017 5:21 pm by Rahul

» When to use Selenium IDE, RC and WebDriver
Mon Feb 13, 2017 2:35 pm by azharuddin

» How to integrate selenium with ZAPI-Zephyr
Sat Feb 11, 2017 2:25 am by gseera002c

» Selenium Webdriver
Sat Feb 04, 2017 6:47 pm by soumyamishrav@gmail.com

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

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

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)

terrynweze

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')");

terrynweze

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