我使用Selenium进行多线程处理,所以我一次要像7-8个窗口一样启动,我希望它们全部彼此对齐,我该如何去做。
我已经尝试过了。 B
x = 20
y = 25
while (x, y < 60):
driver.set_window_position(x, y)
x = x + 10
x = x - 5
y = y + 10
y = y - 15
但是它就像吃豆子游戏一样在屏幕上消失。
答案 0 :(得分:1)
这很容易实现请求。这将打开一个4x2并将每个浏览器放在各自的位置:
from selenium.webdriver import Chrome
# pip3 install screeninfo - might work to get the info but did not work on my macOS
screen_height = 1080
screen_width = 1920
number_of_session = 8
number_per_row = 4
number_per_column = number_of_session / number_per_row
driver_height = screen_height / number_per_column
driver_width = screen_width / number_per_row
drivers = []
row = 0
column = 0
for idx in range(number_of_session):
driver = Chrome()
drivers.append(driver)
driver.set_window_rect(column * driver_width, row * driver_height, width=driver_width, height=driver_height)
if idx + 1 == number_per_row:
row += 1
column = 0
else:
column += 1
for driver in drivers:
driver.close()