[英]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.