本文介绍了Python Selenium测试.如何从Google主页上的搜索框中提取自动建议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一些自动测试Python + Selenium.是否有任何方法可以检查Google中的建议框,例如使用Selenium.就像我现在想要的那样,当自动测试将google放在搜索栏中时,建议表就会显示出来.
I am doing some auto testing Python + Selenium.Is there any way to check suggestion box in google for example using selenium. Something like I would like to now that suggestion table is revealed when auto test put google in search bar.
推荐答案
尝试以下代码:
suggestions = driver.find_elements_by_css_selector("li[class='sbsb_c gsfs']")
for element in suggestions:
print(element.text)
使用for循环遍历所有元素,然后在WebElement上调用 text .
Iterate through all elements using for loop, and call text on WebElement.
这篇关于Python Selenium测试.如何从Google主页上的搜索框中提取自动建议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!