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
Python iFrame未被Selenium Webdriver识别_Python_Selenium_Iframe_Webdriver_Identification - Fatal编程技术网

Python iFrame未被Selenium Webdriver识别

Python iFrame未被Selenium Webdriver识别,python,selenium,iframe,webdriver,identification,Python,Selenium,Iframe,Webdriver,Identification,这是我第一次发布问题。我花了3天多的时间试图找出如何通过webdriver识别iFrame。以下是我的html代码: <iframe id="emailBodyIframe" class="" frameborder="0" src="about:blank" style="height: 151px;"> <html> <head> <body> <p>Dear Administrator,</p> Here is a p

这是我第一次发布问题。我花了3天多的时间试图找出如何通过webdriver识别iFrame。以下是我的html代码:

<iframe id="emailBodyIframe" class="" frameborder="0" src="about:blank" style="height: 151px;">
<html>
<head>
<body>
<p>Dear Administrator,</p>
Here is a passport number : XXXXXXX
<span class="sv-b212-highlighting" style="background-color:#B9DFF5;">aba</span>
#: 0000-0000-0
<p>Regards,</p>
<p>Local Archive</p>
</body>
  • 我得到的错误是
AttributeError:SwitchTo实例没有调用方法

  • 我的问题是
如何识别iFrame中突出显示的CSS

我已经尝试了一些其他的变化与其他代码的例子,是在这个网站上提供的。所有的返回都有不同的错误。我是python新手,还在学习


有人知道我怎么做吗

您需要获取web元素,而使用
FRAME
变量,您希望仅从
iframe
获取文本。请尝试使用以下代码:

self.driver.switch_to_frame("emailBodyIframe")
body1 = self.driver.find_element_by_css_selector("span.sv-b212-highlighting").text
print body1

如果要处理元素,则不必添加
.text
。仅用于从web元素获取文本值

谢谢Andersson。不幸的是,这不起作用。我收到一个错误:NoSuchElementException:Messagetry
body1=self.driver。通过xpath('//span[contains(@class,“highlighting”])查找元素。text
self.driver.switch_to_frame("emailBodyIframe")
body1 = self.driver.find_element_by_css_selector("span.sv-b212-highlighting").text
print body1