Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97811

Find webpage element with changing location, but non-changing text

$
0
0

I am trying to locate an element on a couple of webpages. The webpages are all on the same website, but the structure of the website changes sometimes per page.

When I inspect the pages I see the following full xpaths:

1; /html/body/div[2]/div/div[2]/div/div/main/article/div/div/p[3]/strong/a[1]
2, /html/body/div[2]/div/div[2]/div/div/main/article/div/div/p[10]/a[1]
3; /html/body/div[2]/div/div[2]/div/div/main/article/div/div/p[3]/strong/a
4; /html/body/div[2]/div/div[2]/div/div/main/article/div/div/p[3]/strong/a
5; /html/body/div[2]/div/div[2]/div/div/main/article/div/div/p[3]/strong/a
6; /html/body/div[2]/div/div[2]/div/div/main/article/div/div/p[10]/a[1]
7; /html/body/div[2]/div/div[2]/div/div/main/article/div/div/p[10]/a[1]

with 1, 2, 3, 4, 5, 6, 7

The text of the final element always contains the string Uptobox How do I locate the element each time, even when the structure is different.

Current code (works only for a couple of the above mentioned and has different criterium):

import selenium
from selenium import webdriver

driver = webdriver.Chrome()
driver.get(url)
links = driver.find_elements_by_xpath('//p[contains(., "Download")]//a')  # Need to adjust this to final uptobox-level

Please let me know what I need to adjust

Kind regards,

Huib


Viewing all articles
Browse latest Browse all 97811

Trending Articles