无效参数

无效参数错误是一种 WebDriver 错误,当传递给 命令 的参数无效或格式错误时会发生。

无效参数错误可以类比于 JavaScript 中的 TypeError,因为当输入值不是预期类型或以某种方式格式错误时,它们可能会在许多 API 中发生。有关每个 WebDriver 命令 的类型和范围限制,请参阅相关文档。

示例

例如,无法将窗口大小设置为负值。

python
from selenium import webdriver
from selenium.common import exceptions

session = webdriver.Firefox()
try:
    session.set_window_size(-100, 0)
except exceptions.InvalidArgumentException as e:
    print(e.message)

输出

InvalidArgumentException: Expected -100 to be >= 0

另见