如何使用Selenium WebDriver找到收藏夹按钮并单击它?

2024-05-06 16:29:21 发布

您现在位置:Python中文网/ 问答频道 /正文

更新说明:

这是来自红鳍网https://www.redfin.com/CA/Sunnyvale/735-Grape-Ave-94087/home/1835008,我要找到并单击右上角的“收藏夹”按钮。我尝试过旧描述中的代码以及其他人的所有建议,但都不起作用。在

有人能指导我如何在Selenium webdriver中定位图标吗?在

非常感谢!在

下面的++++++++++++++++++++++++++ 我有这个按钮:

<div role="button" title="Favorite" tabindex="0" class="clickable button tertiary-alt" data-rf-test-name="homeControlButton">
<span><svg class="SvgIcon rfSvg favorite svg-icon-off-color" style="height:24px;width:24px"><svg viewBox="0 0 24 24"></svg></svg></span>
</div>

但是我尝试了find XPath,方法是:

^{pr2}$

但它不起作用。有什么帮助吗?在


Tags: httpssvgdivcomhomewwwbutton按钮
3条回答

这是工作代码。在

WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR , "div[data-rf-test-name='abp-favoriteButton'] div[role='button']")))
driver.find_element_by_css_selector("div[data-rf-test-name='abp-favoriteButton'] div[role='button']").click()

可以使用以下XPath:

//div[@title='Favorite']

希望对你有帮助!在

试试看

browser.find_elements_by_css_selector(".clickable.button.tertiary-alt");

或者你也可以

^{pr2}$

相关问题 更多 >