在 watir-webdriver 中测量表格的像素宽度

发布于 2024-12-29 19:50:20 字数 1962 浏览 3 评论 0原文

有没有办法读取表格的像素尺寸?百分比已显示 width="100%"。如果这有助于探测的话,它位于 div 内部。

我试图获取宽度,然后调整窗口大小以获取 png 屏幕截图(使用已经可用的 Watir 函数)。目前,由于它在页面内显示自己的水平滚动条,因此该表被截断为仅屏幕截图中的前几列,而无论浏览器窗口大小如何,整个页面都会像往常一样垂直显示。

$browser.div(:id, "ctl27_divDetailFrame").table.row.cells.length

=> 23

显示它有 23 列,尽管可能有所不同。

缩小了屏幕字体,

我已经使用$browser.send_keys :home, [:control, "-"], [:control, "-"]

但这还不够,而且字体大小无论如何,不​​应该被减少到被遗忘。

抓取的来源:

<div id="ctl27_divDetailFrame">
    <div class="detail-table-wrapper">
        <div id="ctl27_pnlPositionsTable">
                        <table class="detail-table w-Positions" border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr class="detail-table-head">
                                <td><a class="hpc-column-sort SymbolHeadOSI" href="#" name="DetailSymbolHeader">Symbol</a><span class="common_icon-sort-up-orange_png" title="Sorted Ascending" style="margin-left: 3px; vertical-align:middle;"></span></td>
                                <td class="detail-heading-numeric"><a class="hpc-column-sort SymbolHeadOSI" href="#" name="DetailQuantityHeader">Qty</a></td>
.
.
.
                                <td class="detail-non-numeric"> LAST CELL of table </td>

                            </tr>
                        </table>

                    </div>
    </div>

我在任何地方都没有看到我能够阅读的明确的 width="99999px"

2 更正:在其中一个 css 文件中定义了此类: 而且,之前水平调整页面大小不会将表格的可见性扩展到 830 像素之外。

   div.detail-table-wrapper
    {
        width: 830px;
        overflow: auto;
        overflow-x: auto;
        overflow-y: hidden;
    }

所以现在我想看看是否可以将 widthwatir-webdriver 函数更改为 ~ 95%...(使其与可见屏幕保持一致,这我可以自由调整大小)

Is there a way to read the pixel dimensions of a table? Percentage already shows width="100%". It is inside a div if that helps to probe instead.

I am trying to get the width to then resize the window for a png screenshot (using Watir functions already available). Currently because it shows its own horizontal scrollbar within the page, the table is truncated to only the first few columns in the screenshot, while vertically the entire page appears as usual, regardless of browser window size.

$browser.div(:id, "ctl27_divDetailFrame").table.row.cells.length

=> 23

shows me that it has 23 columns, though that may vary.

I already shrink the screen font a bit with

$browser.send_keys :home, [:control, "-"], [:control, "-"]

but that is not enough, and the font size shouldn't have to be reduced down to oblivion anyway.

The scraped source:

<div id="ctl27_divDetailFrame">
    <div class="detail-table-wrapper">
        <div id="ctl27_pnlPositionsTable">
                        <table class="detail-table w-Positions" border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr class="detail-table-head">
                                <td><a class="hpc-column-sort SymbolHeadOSI" href="#" name="DetailSymbolHeader">Symbol</a><span class="common_icon-sort-up-orange_png" title="Sorted Ascending" style="margin-left: 3px; vertical-align:middle;"></span></td>
                                <td class="detail-heading-numeric"><a class="hpc-column-sort SymbolHeadOSI" href="#" name="DetailQuantityHeader">Qty</a></td>
.
.
.
                                <td class="detail-non-numeric"> LAST CELL of table </td>

                            </tr>
                        </table>

                    </div>
    </div>

Nowhere do I see an explicit width="99999px" which I'd simply be able to read.

2 CORRECTIONs: There is this class defined in one of the css files:
And, horizontal resizing page previously did not extend the table's visibility beyond the 830px.

   div.detail-table-wrapper
    {
        width: 830px;
        overflow: auto;
        overflow-x: auto;
        overflow-y: hidden;
    }

So now I'd like to see if I can change that width to ~ 95% from watir-webdriver functions...(keeping it inline with the visible screen, which I can freely resize)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚你发端 2025-01-05 19:50:20

使用适用于 Firefox 的 Watir-Webdriver,我能够通过以下方式将宽度样式更改为 95%:

$browser.execute_script("document.getElementById('ctl27_divDetailFrame')
      .getElementsByTagName('DIV')[0].style.width='95%';")

请注意,定位器基于 HTML 示例。根据该 ID 是否一致,您可能需要更好的定位器。例如,您可以使用 http:// 为 ID 执行正则表达式www.boards.ie/vbulletin/showthread.php?p=59109660(但我没有测试过)。

旁白:使用 Watir,您可以使用以下代码更直接地执行此操作。然而,作为 Watir-Webdriver 的新手,我找不到类似的 document() 方法。

$ie.div(:index, 2).document.style.width = '95%'

Using Watir-Webdriver for Firefox, I was able to change the width style to 95% with the following:

$browser.execute_script("document.getElementById('ctl27_divDetailFrame')
      .getElementsByTagName('DIV')[0].style.width='95%';")

Note that the locator is based on the HTML sample. Depending on whether that ID is consistent or not, you might need a better locator. For example, you might be able to do a regex for the ID using http://www.boards.ie/vbulletin/showthread.php?p=59109660 (but I have not tested it).

Aside: With Watir, you could more directly do this with the following code. However, being new to Watir-Webdriver, I could not find a similar document() method.

$ie.div(:index, 2).document.style.width = '95%'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文