简体   繁体   English

尽管存在参数 y,但为什么会出现错误“TypeError: set_window_position() missing 1 required positional argument: 'y'”?

[英]Why error “TypeError: set_window_position() missing 1 required positional argument: 'y'” appears despite the argument y is present?

Anyone has an idea why the error appears despite the argument is present?任何人都知道为什么尽管存在论点但仍会出现错误? :) This is my code: :) 这是我的代码:

from selenium import webdriver
import time
import datetime
from selenium.webdriver.chrome.webdriver import WebDriver

opt = webdriver.ChromeOptions()
# opt.add_argument("--start-maximized")

listOfLinks = open("test.txt", "r")
#  open test page in the browser
browser: WebDriver = webdriver.Chrome('C:\\Users\\Valeriia\\PycharmProjects\\selen\\chromedriver.exe', options=opt)
page = browser.get('https://stackoverflow.com/questions/ask')
time.sleep(5)
browser.set_window_position({'x': -4, 'y': -1})
browser.set_window_size({'width': 1448, 'height': 1085})

You provide a dict as a single parameter however the function requires 2 (x and y).您提供dict作为单个参数,但是 function 需要 2(x 和 y)。

Try instead:请尝试:

browser.set_window_position(**{'x': -4, 'y': -1})

or:或者:

browser.set_window_position(x=-4, y=-1)

or:或者:

browser.set_window_position(-4, -1)

You're providing the arguments to browser.set_window_position in a dictionary, but it is expecting the result in a different format.您将 arguments 提供给字典中的browser.set_window_position ,但它期望结果采用不同的格式。 Both of these should work:这两个都应该工作:

browser.set_window_position(x=-4, y=-1)

or或者

browser.set_window_position(-4, -1)

Alternatively, if you store the dictionary somewhere else and pass it in, you can use the double-asterisk syntax to unpack it as a set of keyword arguments:或者,如果您将字典存储在其他位置并传入,您可以使用双星号语法将其解压缩为一组关键字 arguments:

coordinates = {'x':-4, 'y':-1}
browser.set_window_position(**coordinates)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:x 缺少 1 个必需的位置参数:y - TypeError: x missing 1 required positional argument: y TypeError:scatter()缺少1个必需的位置参数:“ y” - TypeError: scatter() missing 1 required positional argument: 'y' Python 出错:TypeError:fit() 缺少 1 个必需的位置参数:'y' - Error with Python: TypeError: fit() missing 1 required positional argument: 'y' 缺少 1 个必需的位置参数:'y' - Missing 1 required positional argument: 'y' scikit-learn-TypeError:fit()缺少1个必需的位置参数:“ y” - scikit-learn - TypeError: fit() missing 1 required positional argument: 'y' 类型错误:flag1() 缺少 1 个必需的位置参数:'y' - TypeError: flag1() missing 1 required positional argument: 'y' 类型错误:predict() 缺少 1 个必需的位置参数:'y_train' - TypeError: predict() missing 1 required positional argument: 'y_train' TypeError: fit() 缺少 1 个必需的位置参数:'y' while GridSearching CNN - TypeError: fit() missing 1 required positional argument: 'y' while GridSearching CNN 实现逻辑回归“TypeError: fit() missing 1 required positional argument: 'y'” - Implementing Logistic Regression “TypeError: fit() missing 1 required positional argument: 'y'” 逻辑回归类型错误:fit() 缺少 1 个必需的位置参数:'y' - Logistic Regression TypeError: fit() missing 1 required positional argument: 'y'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM