【发布时间】:2015-12-23 00:57:08
【问题描述】:
在使用 Python 的 Selenium 中,我一直在尝试从具有子元素的 DIV 选择器中选择文本。代码如下所示:-
<div class="empty-cart-message">
There are no items in this cart.<br>
<button class="btn btn-blue close continue-button continue-empty-btn tmargin10">Continue Shopping</button>
</div>
我需要文本“此购物车中没有商品”。 only ,我正在使用find_element_by_css_selector() 方法。
我面临的问题是,除了我需要的文本之外,它还获取按钮标签内的文本。我使用的代码如下所示:-
cart_status=driver.find_element_by_css_selector("div.empty-cart-message").text
if(assertEqual("There are no items in this cart", cart_status)):
cont_btn=driver.find_element_by_css_selector("button.continue-empty-bin")
cont_btn.click()
我找不到任何可以直接从我使用的方法中消除/取消选择“按钮”文本的内容。
【问题讨论】:
标签: python-2.7 selenium methods selenium-webdriver css-selectors