如何通过python中的分裂或硒将钥匙发送到标签



i试图填充一个使用键按事件的消息框,现在我能够使用Splyter找到该消息框,因此通常该消息框Div是:

       <div aria-autocomplete="list" aria-controls="js_7" aria-
    describedby="placeholder-cmsmo" aria-expanded="false" aria-label="Type
 a message..." class="notranslate _5rpu" contenteditable="true" 
role="combobox" spellcheck="true" tabindex="0" style="outline: none; user-
select: text; white-space: pre-wrap; word-wrap: break-word;"><div data-
contents="true"><div class="" data-block="true" data-editor="cmsmo" data-
offset-key="7qui-0-0"><div data-offset-key="7qui-0-0" class="_1mf _1mj">
<span data-offset-key="7qui-0-0"><br data-text="true"></span></div></div>
</div></div>

但是,当我键入某些内容时,文本会在"<span>"text"</span>"之间进行类似:

    <div aria-autocomplete="list" aria-controls="js_7" aria-
expanded="false" aria-label="Type a message..." class="notranslate _5rpu"
 contenteditable="true" role="combobox" spellcheck="true" tabindex="0" 
style="outline: none; user-select: text; white-space: pre-wrap; word-wrap: 
break-word;"><div data-contents="true"><div class="" data-block="true" 
data-editor="cmsmo" data-offset-key="98vvu-0-0"><div data-offset-
key="98vvu-0-0" class="_1mf _1mj"><span data-offset-key="98vvu-0-0"><span 
data-text="true">hello this is example text</span></span></div></div></div>
</div>

所以现在我可以在Python中找到这样的跨度标签:

d ="""//*[@id="actual_id"]/div[2]/div[2]/div[2]/div[1]/div/div[1]/div/div[1]/div/div[2]/div/div/div/div/span"""

span_tag=browser.find_by_xpath(d)


for i in span_tag:
    print(span_tag["data-offset-key"])

结果:

98vvu-0-0

因此,这意味着我现在找到了跨度标签,如何通过Splinter或Selenium发送键以填充该跨度标签,因此自动在该消息框中键入?

我尝试了这样的两种方法:

span_tag=browser.find_by_xpath(d1)

span_tag.send_keys("hello this is example")

第二

span_tag=browser.find_by_xpath(d1)


for i in span_tag:
    print(i.send_keys("hello this is example"))

但是,在两种情况下,我都会遇到此错误:

Traceback (most recent call last):
  File "/anaconda/lib/python3.5/site-packages/splinter/element_list.py", line 72, in __getattr__
    return getattr(self.first, name)
AttributeError: 'WebDriverElement' object has no attribute 'send_keys'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Users/dname/Downloads/pythoncrawling/requested1.py", line 53, in <module>
    span_tag.send_keys("hello this is example")
  File "/anaconda/lib/python3.5/site-packages/splinter/element_list.py", line 75, in __getattr__
    self.__class__.__name__, name))
AttributeError: 'ElementList' object has no attribute 'send_keys'

碎片看起来很早就在开发中,并且没有您期望从普通的selenium python apis(包括send_keys)获得的所有API。我会抛弃分裂,如果我是你,请使用普通绑定。

http://splinter.readthedocs.io/en/latest/api/driver-and-element-element-element-empi.html#elementapi

在此处或其他任何对象的其他API中都没有提及send_keys。

span_tag.first._element.send_keys(...)

参考内部硒元素。

相关内容

  • 没有找到相关文章

最新更新