我想点击 mt4 web terminal 中的“新订单”图标在 python 中使用 selenium 模块
这是代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome('./chromedriver')
driver.get("https://www.mql5.com/en/trading")
new_order = driver.find_element_by_xpath('/html/body/div[3]/div[1]/a[1]/span[1]')
new_order.click()
这是我得到的错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[3]/div[1]/a[1]/span[1]"}
(Session info: chrome=86.0.4240.198)
找到该按钮的正确方法是什么,我搜索并找到了一些方法来定位 selenium 的元素,但我无法找到任何适合我的方法。
最佳答案
看起来您的页面正在处理 iframe。所以虽然 above answer有好的做法,你还需要切换到iframe:
driver.switch_to.iframe(self,frame reference)
在 https://www.techbeamers.com/switch-between-iframes-selenium-python/ 中查找更多详细信息或 https://stackoverflow.com/a/24286392/1387701
关于Python Selenium,帮助我定位网站中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64862700/