0
硒使用find_element_by_css_selector从子元素消除文本()方法中,我一直在试图选择具有子元素的DIV选择文本well.The代码如下所示: -硒的Python:使用Python
<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>
我需要文本“此购物车中没有物品。”只是,我正在使用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()
“按钮的”直接从我使用的方法文本。
作为告诉@ mahsum-akbas(他的回答上面),我尝试使用JavaScript executor.But,**方法**'driver.execute_script()'返回**没有值** –
我在我的本地尝试了相同的html和python并且可以在输出中看到文本。 –
我做了同样的@ mahsum-akbas!脚本运行时没有显示任何错误,但'execute_script()'返回一个空白的** String **。它是否需要在您可能使用的特定版本的** Selenium或Python或任何其他浏览器**上进行测试? –