问题
I am new to selenium in python. I am searching the supreme website by keywords using Xpath as such:
WebDriverWait(driver, 5).until(EC.element_to_be_clickable(
(By.XPATH, "//a[contains(text(),'Supreme Time Tee')]"))).click()
My question is how would I search keywords for any text and skip until it finds it? For example, I struggle to grab the t shirt labeled "Dragon Tee Heather Grey" that is split into two a href link tags "Dragon Tee" and "Heather Grey".
I want to be able to click either element but I am not sure how to construct this.
回答1:
can you try this xpath:
//a[contains(text(),'Dragon Tee')] /parent::div/following-sibling::*/a[contains(text(),'Dusty')]
回答2:
You can use XPath to solve this by looking for sibling tags. For example, if you want to find the Dragon Tee Heather Grey link, you can use this.
driver.find_element_by_xpath('//div[a/text() = "Dragon Tee"]/following-sibling::div[a/text() = "Heather Grey"]')
来源:https://stackoverflow.com/questions/61354961/how-to-search-a-webpage-using-selenium-by-any-of-the-keywords-inputted