gpt4 book ai didi

linux - 如何自动获取 xdotool 的窗口 ID

转载 作者:太空狗 更新时间:2023-10-29 11:18:09 24 4
gpt4 key购买 nike

我正在尝试自动测试 selenium 会花费太长时间的表单(javascript 繁重的现代表单),我想使用 xdotool 并获取窗口 ID。我看到您可以调用 xdotool selectwindow 并单击它,但是每次都必须单击它。我想告诉它“对于标签标题为 x 的 google chrome 窗口,执行 y”

我在这里得到了窗口 ID:

cchilders@cchilders-Dell-Precision-M3800:~$ xdotool selectwindow
65011713

这是针对 chrome 本身的,每个选项卡在单击时都会获得相同的值。所以我希望在 ps 或窗口管理器中找到它,但没有:

cchilders@cchilders-Dell-Precision-M3800:~$ wmctrl -l
0x03a00001 0 cchilders-Dell-Precision-M3800 views.py - /home/cchilders/work_projects - Atom
0x03a00048 0 cchilders-Dell-Precision-M3800 pip_freeze_update.py - /home/cchilders/scripts - Atom
0x03a000bc 0 cchilders-Dell-Precision-M3800 urls.py - /home/cchilders/work_projects - Atom

ps 也不起作用:

(clientsite)cchilders@cchilders-Dell-Precision-M3800:~$ ps -alx
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
4 0 1 0 20 0 185188 5752 ep_pol Ss ? 0:06 /sbin/init splash
1 0 2 0 20 0 0 0 kthrea S ? 0:00 [kthreadd]
1 0 3 2 20 0 0 0 smpboo S ? 0:02 [ksoftirqd/0]
1 0 5 2 0 -20 0 0 worker S< ? 0:00 [kworker/0:0H]
1 0 7 2 20 0 0 0 rcu_gp S ? 1:10 [rcu_sched]
1 0 8 2 20 0 0 0 rcu_gp S ? 0:00 [rcu_bh]
...etc...

65011713 没有出现。 Xdotool 是一个很棒的工具,但是窗口操作需要您对窗口有很多了解,根据我之前使用它的内存,https://www.semicomplete.com/projects/xdotool/xdotool.xhtml#window_commandsWINDOW COMMANDS 部分|有很多方法可以找到您非常了解的窗口,但在自动获取该窗口信息方面却不多。我如何自动确定窗口 ID(xdotool 想要的格式),比如通过在 URL 的开头部分提供脚本?谢谢

您可以在 wmtrl 中查找 Google Chrome:

(scripts)cchilders@cchilders-Dell-Precision-M3800:~/scripts/bash$ wmctrl -l
0x03e00001 0 cchilders-Dell-Precision-M3800 Edit - Stack Overflow - Google Chrome
...

并获取由空格分隔的第一个数字到 int:

In [13]: int("0x03e00001", 16)
Out[13]: 65011713

int 中的 16 标志告诉它期待十六进制

In [14]: int("0x03e00001")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-14-96517b980767> in <module>()
----> 1 int("0x03e00001")

ValueError: invalid literal for int() with base 10: '0x03e00001'

最佳答案

您可以使用 xdotool 按名称、窗口类等查找窗口。要按名称搜索窗口,请使用:

xdotool search --name 'My Window Name'

这会将十进制窗口 ID 打印到标准输出。 --name 标志匹配部分或全部窗口名称。在浏览器中,这通常包括当前选项卡名称。 xdotool也可以这样返回对应的pid:

xdotool search --name 'My Window Title' getwindowpid

他是一个向窗口发送一系列按键和鼠标点击的例子。

# Find window with title containing 'My Window Title, activate it,
# move the mouse to coordinates 200x400, left click, then press F5
xdotool search --name 'My Window Title' windowactivate mousemove 200 400 click 1 key F5
# Store window id of the active window
WINDOW_ID=$(xdotool getactivewindow)
# Type a series of characters into the window
xdotool type "this text is being typed into window" --window $A

关于linux - 如何自动获取 xdotool 的窗口 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34207981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com