selenium使用python 3识别元素
使用selenium for python 3识别以下web元素时遇到问题:selenium使用python 3识别元素,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,使用selenium for python 3识别以下web元素时遇到问题: <button data-original-title="Reply" class="ProfileTweet-actionButton u-textUserColorHover js-actionButton js-actionReply js-tooltip" data-modal="ProfileTweet-reply" type="button"> 我必须使用哪种方法? 代码是什么样子的?有多
<button data-original-title="Reply" class="ProfileTweet-actionButton u-textUserColorHover js-actionButton js-actionReply js-tooltip" data-modal="ProfileTweet-reply" type="button">
我必须使用哪种方法?
代码是什么样子的?有多种方法可以找到依赖于不同元素属性的元素 我将依赖
数据原始标题
属性并使用:
或者,使用数据模式
属性:
driver.find_element_by_xpath('//button[@data-modal="Reply"]')
或者,您可以组合这些表达式并制作自己的表达式
另一种策略和替代解决方案的示例是使用“CSS选择器”,例如:
driver.find_element_by_css_selector('button.ProfileTweet-actionButton')
python一直告诉我找不到元素:-(@123页上有
iframe
或frame
元素吗?页上有iframes元素。@123如果此按钮位于iframe内,首先需要切换到该iframe,例如驱动程序。切换到.frame('frame\u id\u或\u name')
。
driver.find_element_by_css_selector('button.ProfileTweet-actionButton')