gpt4 book ai didi

python - 在 Python/SST 自动化脚本中使用 Selenium 函数

转载 作者:行者123 更新时间:2023-11-28 17:46:00 25 4
gpt4 key购买 nike

那里有高级自动化人员吗?我正在使用 Python 和 SST 编写自动化脚本,但我遇到了 SST 的一些限制。我想从标准 Selenium 库中借用一个函数在我的脚本中使用,我在其中双击一行文本以突出显示它。我在脚本的开头使用 SST 创建了一个 webdriver 实例,并开始在网页上执行操作。我的问题是:有什么方法可以与 Selenium 函数共享该实例以执行此操作。我意识到我可以在 Selenium 中完成整个脚本,但我工作的公司致力于 SST,因此不会被接受。不过,如果我加入一个 Selenium 函数,我认为没有人会介意。由于 SST 是建立在 Selenium 之上的,我想一定有一个新的类已经编写好了,我可以导入它来执行这样的操作。我想要执行的代码如下所示。但是当然,当我用 Selenium 创建第二个 webdriver 实例时,会打开一个新的浏览器,然后脚本在逻辑上分成两半。有什么建议吗?

from sst.actions import *
from selenium import webdriver
from selenium.webdriver.firefox.webdriver import *
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import *

go_to('http:/yadayada.net/')
## perform a bunch of actions
text = ## get text element with SST

driver = webdriver.Firefox()
action = ActionChains(driver)
action.double_click(text)
action.perform()

最佳答案

要访问底层 webdriver,您需要引用:

sst.actions._test.browser

这是一个 SST 的例子直接使用 webdriver.Firefox 实例的脚本:

import sst.actions

# a regular SST action
sst.actions.go_to('http:/testutils.org/sst')

# now using webdriver directly
sst.actions._test.browser.get('http://www.python.org')

你问题中的例子可以写成:

from sst.actions import *
from selenium.webdriver.common import action_chains

go_to('http:/yadayada.net/')
## perform a bunch of actions
text = ## get text element with SST

driver = sst.actions._test.browser
action = action_chains.ActionChains(driver)
action.double_click(text)
action.perform()

关于python - 在 Python/SST 自动化脚本中使用 Selenium 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18130839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com