首页 > 解决方案 > Selenium Python - javascript函数调用

问题描述

我如何在 Selenium Python 中调用 javascript 函数?

我正在尝试单击这样的按钮:

<a href="javascript:;" class="btndefault j-open-game j-gamingButton" data-gameid="1280" data-productid="2" ...> 

但如果我搜索它:

btn = browser.find_element_by_class_name('btndefault j-open-game j-gamingButton')

我收到:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".btndefault j-open-game j-gamingButton"}

如果我搜索它:

btn = browser.find_element_by_xpath("//button[@name='j-gamingButton']")

我收到:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@name='j-gamingButton']"}

如果我搜索它:

btn = browser.find_element_by_xpath("//button[@name='j-btndefault j-open-game j-gamingButton']")

我收到:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@name='j-btndefault j-open-game j-gamingButton']"}

如果我搜索它:

btn = browser.find_element_by_xpath("//button[@class='j-btndefault j-open-game j-gamingButton']")

我收到:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:

你对我有什么建议吗?提前致谢

标签: javascriptpythonselenium

解决方案


推荐阅读