2017-03-08 45 views

回答

0

的XPath應該能夠幫助您在選擇基於h1和p標籤屬性的特定項目:

//p/a[text()='Red']/parent::p/preceding-sibling::h1/a[text()='Script Logo 6-Panel']/parent::h1/preceding-sibling::a[1] 

讓我知道,它是否適合你。

0

您可以使用xpath檢查條件。如果找到滿足條件的元素,然後點擊它

// xpath for element satisfying the condition 
String xpath = "//h1/a/[text()= 'Script Logo 6-panel']/../following-sibling::p[1]/a[text()='Red']" 

// find the element 
List<WebElement> elements = driver.findElements(By.xpath(xpath)); 

// If element is found, click on it. 
if (elements.size()!=0) { 
    elements.get(0).click(); 
} 

上面的代碼是在java中。但同樣可以在python中實現。