[英]Can't send_keys to td in selenium python (no input tag available)
I can find the element and click on it: 我可以找到该元素并单击它:
driver.find_element_by_xpath("//*[@id='tinymce']/table/tbody/tr[2]/td[1]").click()
When I try to send_keys to it with: 当我尝试使用以下命令发送send_keys时:
driver.find_element_by_xpath("//*[@id='tinymce']/table/tbody/tr[2]/td[1]").send_keys("test")
I get 我懂了
Traceback (most recent call last):
File "C:\Users\jlesslar\Documents\Scripts\post robot automater.py", line 60, in <module>
driver.find_element_by_xpath("//*[@id='tinymce']/table/tbody/tr[2]/td[1]").send_keys("test")
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: unknown error: cannot focus element
(Session info: chrome=72.0.3626.81)
(Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64)
As far as I cant tell the td is where I want to send_keys to but online it says I should either have a text field or input tag available to me for send_keys to work (which I do not) 据我无法告知td是我想要send_keys到的地方,但在网上它说我应该有一个文本字段或输入标签对我可用,以便send_keys可以工作(我不想要)
Guidance would be much appreciated.Thanks! 指导将不胜感激。谢谢!
You should be able to change the innerHTML value by using a JS using execute_script() 您应该能够通过使用execute_script()的JS来更改innerHTML值
First get your element: 首先获取您的元素:
el = driver.find_element_by_xpath("//*[@id='tinymce']/table/tbody/tr[2]/td[1]")
Then try by setting directly the innerHTML value: 然后尝试直接设置innerHTML值:
driver.execute_script('arguments[0].innerHTML = "test";', el)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.