1

I found the following XPath expression using FirePath and Firebug:

//div[@class='itudeBox floatDiv']/div[1]/div/text()[2]

This returns the correct value in Selenium.

But when I try the same in EclipseTestNG:

selenium.getAttribute("xpath=//div[@class='itudeBox floatDiv']/div[1]/div/text()[2]");

It shows an error "Element not found".

How can I fix this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user1254309
  • 21
  • 1
  • 3
  • Its a huge HTML file. With lot of characters. If I paste it here it will look confusing to you. May be can I post it to your mail ID? If yes can you please provide me your ID? – user1254309 Mar 09 '12 at 12:37
  • Ok now I tried this : selenium.getText("xpath=//div[@class='itudeBox floatDiv']/div[1]/div/text()[2]"); And it says "ERROR: This element has no value; is it really a form field?" Any info on this issue? – user1254309 Mar 09 '12 at 12:40
  • dont provide whole HTMl..just provideHTML related to element which you are trying to identify – Rohit Ware Mar 09 '12 at 12:42
  • Here you go : Am trying to find the text "AD- Advice" Am pasting it in 6 comments here because of the character limit to add a comment. Please combine them. Thanks – user1254309 Mar 09 '12 at 13:01
  • {Richfaces.componentControl.performOperation(event,'oncomplete','#page_form\\:deviation_modalpanel','show')},'similarityGroupingId':'page_form:j_id1076:monitor_form:monitor_board_list_table:0:table_details_region:deviation_panel_new_deviation','parameters': – user1254309 Mar 09 '12 at 13:02
  • {'page_form:j_id1076:monitor_form:monitor_board_list_table:0:table_details_region:deviation_panel_new_deviation':'page_form:j_id1076:monitor_form:monitor_board_list_table:0:table_details_region:deviation_panel_new_deviation','ajaxSingle':'page_form:j_id1076:monitor_form:monitor_board_list_table:0:table_details_region:deviation_panel_new_deviation'} ,'containerId':'page_form:j_id1076:monitor_form:monitor_board_list_table:0:table_details_region'} );return false;" style="float: none; margin-left: auto; margin-right: auto;">Add a deviation – user1254309 Mar 09 '12 at 13:03
  • {Richfaces.componentControl.performOperation(event,'oncomplete','#page_form\\:deviation_modalpanel','show')},'similarityGroupingId':'page_form:j_id1076:monitor_form:monitor_board_list_table:0:table_details_region:j_id1629:0:j_id1646','parameters':{'page_form:j_id1076:monitor_form:monitor_board_list_table:0:table_details_region:j_id1629:0:j_id1646':'page_form:j_id1076:monitor_form:monitor_board_list_table:0:table_details_region:j_id1629:0:j_id1646'} – user1254309 Mar 09 '12 at 13:04
  • ,'containerId':'page_form:j_id1076:monitor_form:monitor_board_list_table:0:table_details_region:j_id1628'} )"> 3/8/12 3:05 PM - Costs - interfaceflor - € 5.00
    AD - Advice
    – user1254309 Mar 09 '12 at 13:04
  • Can u please edit that into your post? – Tarken Mar 09 '12 at 13:26
  • I am getting element not found exception on these two elements :

    –  Oct 17 '15 at 07:58

2 Answers2

1

Try out the below one to locate the element:

//div[text()='AD- Advice']
css=div:contains(“AD- Advice”)
//div[contains(text(),'AD- Advice')]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rohit Ware
  • 1,982
  • 1
  • 13
  • 29
  • I tried like you said. But all there are failing //invalid xpath //selenium.getAttribute("xpath=//div[text()='AD- Advice']"); //element not found //selenium.getAttribute("css=div:contains(“AD- Advice”)"); selenium.getAttribute("xpath=//div[contains(text(),'AD- Advice')]"); – user1254309 Mar 09 '12 at 13:32
  • selenium.getAttribute("//div[text()='AD- Advice']") – Rohit Ware Mar 09 '12 at 13:43
  • 1
    I got it working. selenium.getText("//div[@class='itudeBox floatDiv']/div[1]/div/text()[2]"); Thank you so much for your time – user1254309 Mar 09 '12 at 13:55
  • A single XPath expressions? Three separate XPath expressions? What is the intent? – Peter Mortensen Nov 19 '22 at 00:21
1

Try this:

selenium.getText("xpath=//div[@class='itudeBox floatDiv']/div[1]/div");

Or:

selenium.getText("xpath=//div[@class='itudeBox floatDiv']/div[1]/div[2]");

The getText() method works on the element and I believe your XPath expression returns the text within an element.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cliff Darling
  • 225
  • 1
  • 3