小编sas*_*iko的帖子

XCTest() 获取 XCUIElement 的父级

这是我po print(XCUIApplication().debugDescription)在终端窗口中输入时尝试打印应用程序元素结构时的示例

tables, (address code like 0x00006b), traits: (some random number)
    cells, (address code), traits: (random number)
       others, (address code), traits: (random number), label: "Other Value"
       buttons, (address code), traits: (random number), identifier: "primaryButton", label: "Press ME"
Run Code Online (Sandbox Code Playgroud)

所以,基本上,如果我想访问others价值,我只需要通过它的标签简单地访问:

let cellsValue = XCUIApplication().tables.cells.otherElements.staticTexts["Other Value"];

但是,问题是staticTexts可以超时更改,所以我的解决方案是我可以访问具有特定标识符的元素,例如:

let btnPrimary = XCUIApplication().tables.buttons["primaryBtn"];
Run Code Online (Sandbox Code Playgroud)

并调用它的父级(在这种情况下为单元格元素),例如:

let tableParent = btnPrimary.parent() 
Run Code Online (Sandbox Code Playgroud)

这样我就可以使用以下方法轻松访问该元素:

let otherElement = tableParent.otherElements.firstMatch.label
Run Code Online (Sandbox Code Playgroud)

但是该parent()函数不存在,那么我如何才能访问元素的父元素?

automation automated-tests xctest swift

4
推荐指数
1
解决办法
3015
查看次数

重载C++赋值运算符的返回值

我是 C++ 新手,我从 learncpp 网站开始。在赋值运算符重载章节中有这些代码行:

Fraction& Fraction::operator= (const Fraction &fraction)
{
    m_numerator = fraction.m_numerator;
    m_denominator = fraction.m_denominator;
    return *this;
}
Run Code Online (Sandbox Code Playgroud)

首先是为什么重载赋值必须返回引用而不是值?

第二件事是,由于this是 指针本身,因此*this将表示为取消引用,因此它的值应该是 object,但赋值运算符的返回值是Fraction&。我这里是不是有什么误解?

c++ operator-overloading

1
推荐指数
1
解决办法
1495
查看次数