selenium无法定位元素,而元素正好位于

2024-06-25 06:51:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用selenium自动输入http://ueditor.baidu.com/website/examples/completeDemo.html中的HTML代码。我的程序是先单击html,然后编写html代码,而IDE总是告诉我找不到元素。在点击HTML Button之后,元素是正确的there,但总是出错,这让我抓狂。我只是想知道我怎么能写在框后,点击HTML按钮使用硒?多亏了那个热心人

import os,time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

chromePath = r'E:/Python/WEB/web-infor-transfer/monidenglu/chromedriver.exe'
wd = webdriver.Chrome() 
loginUrl = 'http://ueditor.baidu.com/website/examples/completeDemo.html' 
wd.get(loginUrl) 


wd.find_element_by_xpath('//*[@id="edui4"]').click()


time.sleep(2)


wd.find_element_by_xpath('//*[@id="edui1_iframeholder"]/div/div[2]/div/div/div[2]/div/div[2]').send_keys('hello')

   time.sleep(5)
   wd.quit()

Tags: fromimportdivcomhttptimehtmlselenium
1条回答
网友
1楼 · 发布于 2024-06-25 06:51:56

试试动作链。例如,将密钥发送到浏览器本身就起作用:

wd.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div/div[2]/div/div/div[2]/div/div[2]/pre[2]/span').click()
actions = ActionChains(wd)
actions.send_keys('hello')
actions.perform()

相关问题 更多 >