Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
selenium使用python 3识别元素_Python_Selenium_Selenium Webdriver - Fatal编程技术网

selenium使用python 3识别元素

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"> 我必须使用哪种方法? 代码是什么样子的?有多

使用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">

我必须使用哪种方法?
代码是什么样子的?

有多种方法可以找到依赖于不同元素属性的元素

我将依赖
数据原始标题
属性并使用:

或者,使用
数据模式
属性:

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')