browser = webdriver.Firefox()
browser.get("http://www.example.com/admin/orders")
total_images = len(browser.find_elements_by_xpath('/html/body/div[5]/div[3]/div[1]/div[3]/div[4]/form[1]//img'))
for i in range(1,total_images):
compiledData['item_url'] = browser.find_elements_by_xpath(browser.xpath('/html/body/div[5]/div[3]/div[1]/div[3]/div[4]/form[1]//img[')+str(']'))
Now what I need is the actual path of the element. As you can see that I am looping through the range of images within a dynamic xpath code. Now if I am in a loop and there I need the exact xpath
of that current dynamically identified image xpath
For example, if it is running for the first image then it should give:
/html/body/div[5]/div[3]/div[1]/div[3]/div[4]/form[1]/img[1]
if it's running for second time then:
/html/body/div[5]/div[3]/div[1]/div[3]/div[4]/form[1]/img[2]
I want to extract this actual xpath
of that current node within that loop
Now something like the PHP one:
$breakup = $xpath->query('/html/body/div[5]/div[3]/div[1]/div[3]//*[text()="Package total"]');
if($breakup->length != 0)
{
$breakupPath = substr($breakup->item(0)->getNodePath(), 0, -2)."2]";
$orderData['total'] = str_replace("Rs.", "", trim($xpath->query($breakupPath)->item(0)->nodeValue));
}
Where, $breakup->item(0)->getNodePath()
gives the real xPath
of the dynamically identified xPath