我知道它是新的,但我喜欢点击很多的外观并且很想使用它,但我无法弄清楚如何将变量从main方法传递给其他方法.我使用不正确,还是这个功能还没有?看起来非常基本,所以我确信它会在那里,但这些事情只是出现了一段时间,所以也许不是.
import click
@click.option('--username', default='', help='Username')
@click.option('--password', default='', help='Password')
@click.group()
def main(**kwargs):
print("This method has these arguments: " + str(kwargs))
@main.command('do_thingy')
def do_thing(**kwargs):
print("This method has these arguments: " + str(kwargs))
@main.command('do_y')
def y(**kwargs):
print("This method has these arguments: " + str(kwargs))
@main.command('do_x')
def x(**kwargs):
print("This method has these arguments: " + str(kwargs))
main()
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,我如何获得其他方法可用的用户名和密码选项
我正在尝试选择一些文本(即用鼠标光标突出显示它)进行自动化测试。我想使用 Python 和 webdriver 访问此网址:http://en.wikipedia.org/wiki/WebDriver#Selenium_WebDriver并突出显示标题“Selenium WebDriver”下的第二句话(“Selenium WebDriver 接受命令(发送到Selenese,或通过客户端 API)并将它们发送到浏览器。”)
棘手的是,我希望这可以在不使用任何元素的情况下完成,并且我一直在尝试找出一种方法来单击 x 和 y 坐标指定的位置,然后按住移动到由一组不同的 x 和 y 坐标。
通过阅读,我了解到,当您需要指定一个元素时,不可能仅通过坐标单击页面的某个区域,因此可以仅使用单个远程元素(比方说“. mw-editsection>a")? 我认为可以通过使用该元素作为参考并单击距其一定距离(即按偏移量单击)来完成此操作。
这是我到目前为止所尝试的,但它没有完成这项工作:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Firefox()
actions = ActionChains(driver)
driver.get("http://en.wikipedia.org/wiki/WebDriver#Selenium_WebDriver")
the_only_element = ".mw-editsection>a"
element = driver.find_element_by_css_selector(the_only_element)
actions.move_to_element_with_offset(element,50,50)
actions.click_and_hold(on_element=None)
actions.move_by_offset(50, 50)
actions.release()
actions.perform()
Run Code Online (Sandbox Code Playgroud)
由此,我得到这个错误:
WebDriverException: Message: u"'UnknownError: Cannot press more then one button or an already pressed button.' when calling method: [wdIMouse::down]"
Run Code Online (Sandbox Code Playgroud)
我明白上面的例子有点做作,但我实际上无法向您提供我真正想要测试的东西。我实际上正在做的是使用 webdriver 在 Python 中编写一系列测试来测试我们的文档查看器,并且我确实需要能够突出显示一行文本,因为这是在我们的系统上添加注释的方式。不幸的是,文档查看器实际上并不显示提交的文档,仅通过某种 JavaScript 魔法显示它的图像。文档页面是一个元素,但页面本身没有可供 Webdriver 单击的元素。 …