Настройка узла контекста xpath в Python 3 Selenium Webdriver - PullRequest
0 голосов
/ 04 июля 2018

Я хотел бы выполнить повторные поиски xpath для определенного узла. Как установить этот узел в качестве контекста в веб-драйвере python selenium?

from selenium import webdriver
d=webdriver.Chrome()
d.get("mysitehere")
d.SET(context_node) <--what goes here?
d.find_element_by_xpath("descendant::xxx[contains(text(), 'my text')]")
d.find_element_by_xpath("descendant::xxx[contains(text(), 'my other text')]")

1 Ответ

0 голосов
/ 04 июля 2018

Вам нужно что-то вроде ниже:

context = d.find_element_by_xpath("//*[@attr='value']")  # define context node

# Define descendants of context node
context.find_element_by_xpath("./descendant::xxx[contains(text(), 'my text')]")
context.find_element_by_xpath("./descendant::xxx[contains(text(), 'my other text')]")

Обратите внимание, что вам нужно указать точку в начале выражения XPath, чтобы указывать на узел контекста

...