How to get particular value from inside div element?

Hi everyone

Is there any method to get value inside div element? (div inside div)

<div class="inventory_item" style="">
	<div class="inventory_item_img" style="">
		<a href="#" id="item_4_img_link">
			<img alt="Sauce Labs Backpack" class="inventory_item_img" src="/static/media/sauce-backpack-1200x1500.0a0b85a3.jpg" style="">
		</a>
	</div>
<div class="inventory_item_description" style="">

I found this to “get and store” value from the Object repository.
InventoryImage = WebUI.getAttribute(findTestObject('Object Repository/Pathway of item_4_img_link'), 'src')
using the object in line 3 (item_4_img_link) to get the value of “src”.

Is it possible to get the value “src” using the object of line 1 as an Object Repository.??

1 Like

I would recommend you to study the XPath technology by reading some good tutorial, for example:

1 Like

Try this

String js = 'return document.querySelector("#item_4_img_link img").src'
String src = WebUI.executeJavaScript(js, null)

println src

Ah, @Russ_Thomas’ reply told me what the original question was asking.

@setiawanandro

Change the locator in the “Object Repository/Pathway of item_4_img_link”

from (possibly)

//a[@id='item_4_img_link']

to

//a[@id='item_4_img_link']/img