【发布时间】:2020-04-16 01:47:17
【问题描述】:
我有一个按钮搜索,它会显示“未找到结果”或“另一个购买按钮”。
我要做的是创建一个if 以检查页面上是否有“未找到结果”,单击返回按钮。如果没有,请点击购买按钮。
这是 HTML 代码:
<button> Search </button>
..
<div class="contents"> <h2>No results found<h/2> </div> #the message I want to check first
..
<button class="btn-standard> Buy Now </button> #buy button
...
<button class="back"> Back </button> #the button I want to click if no resul
我已经尝试过类似以下的方法:
if driver.find_element_by_xpath('//h2[text()="No results found"]'):
driver.find_element_by_class_name('back').click()
else:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(., 'Buy Now')]"))).click()
但它没有用。我必须使用try / catch 编码吗?
另一个编辑:
我现在收到此错误。我不知道如何隐藏那个遮住我的购买按钮的元素。
ElementClickInterceptedException: Message: Element <button class="btn-standard buyButton"> is not clickable at point (1086,641) because another element <div class="ut-click-shield showing interaction"> obscures it
【问题讨论】:
标签: python python-2.7 selenium selenium-webdriver selenium-chromedriver