本文介绍了如何自动获取xdotool的窗口ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动化测试硒会花费太长时间的表单(JavaScript繁重的现代表单),并且我想使用xdotool并获取窗口ID.我看到您可以调用 xdotool selectwindow 并单击它,但是每次都必须单击它.我想告诉它对于选项卡标题为x的谷歌浏览器chrome窗口,请执行y"

I am trying to automate testing forms that selenium would take too long (javascript heavy modern forms), and I want to use xdotool and get window IDs. I see you can call xdotool selectwindow and click it, but then you have to click it each time. I want to tell it "for google chrome windows where the tab title is x, do y"

我在这里获得了窗口ID:

I got the window ID here:

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

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

This is for chrome itself, each tab gets the same value when clicked. So I expected to find that in ps or a window manager, but no:

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是一个很棒的工具,但是窗口操作希望您对窗口有很多了解,而根据我以前使用它的经验,请参阅WINDOW COMMANDS "部分./www.semicomplete.com/projects/xdotool/xdotool.xhtml#window_commands"rel =" nofollow> https://www.semicomplete.com/projects/xdotool/xdotool.xhtml#window_commands 有很多查找窗口的方法很多,但是自动化获取窗口信息的方法却不多.我如何自动确定窗口ID(xdotool想要的格式),例如通过向URL的开头部分输入脚本?谢谢

nowhere does 65011713 show up. Xdotool is a great tool, but the window manipulation expects you to know a lot about the windows, and from what I remember of using it before, the WINDOW COMMANDS section of https://www.semicomplete.com/projects/xdotool/xdotool.xhtml#window_commands has a lot of ways to find a window you know a lot about, but not much in the way of automating getting that window info. How can I determine the window ID (the format xdotool wants) automatically, say by feeding a script the beginning portion of a URL? Thank you

您可以在wmtrl中查找Google Chrome:

You can look for Google Chrome in the wmtrl:

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

并抓取第一个数字,并用空格分隔为int:

and grab the first number separated by space to int:

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

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

The 16 flag in int tells it expect hexadecimal

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'

推荐答案

您可以使用 awk wmctrl -l 的输出中提取ID.

You can use awk to extract the ID from the output of wmctrl -l.

例如:

wmctrl -l | awk '/Google Chrome/ {print $1}'

xdotool 可能会认为十六进制ID很好,但如果不能,则可以使用 strtonum 将其转换为十进制表示形式:

xdotool will likely take that hex IDs just fine but if it can't you can convert that to the decimal representation with strtonum:

wmctrl -l | awk '/Google Chrome/ {print strtonum($1)}'

如何匹配恰好要从 awk 的输出中获得所需的窗口,取决于您和您的要求.

How you match just the window you want from the output in awk is up to you and your requirements.

可能值得注意的是, xdotool 似乎也有一个 search 命令,该命令带有各种说明符和模式,可用于获取Windows的窗口ID.您要对其进行操作.(它甚至支持一堆匹配项,它支持窗口ID"的特殊格式,可以直接对链接的命令"进行操作.)

It is probably worth noting that xdotool also appears to have a search command which takes all sorts of specifiers and patterns that you can use to get the window ID of windows you want to operate on. (It even supports a stack of matches that it supports a special format of "window ID" to operate on directly for "chained commands".)

这篇关于如何自动获取xdotool的窗口ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 15:44