Skip to content

Enable searching QML elemnts by objectName from JavaScript #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hekra01 opened this issue Jun 1, 2015 · 5 comments
Closed

Enable searching QML elemnts by objectName from JavaScript #6

hekra01 opened this issue Jun 1, 2015 · 5 comments

Comments

@hekra01
Copy link
Contributor

hekra01 commented Jun 1, 2015

wd.executeScript(string) can be used to find qml elements by object name
8498ab2

e.g:
with such qml

Rectangle {
    id: button
    objectName: "button"
    Text {
        id: buttonText
        objectName: "buttonText"
        text: parent.description
        font.pixelSize: parent.height * .5
    }
}

then such selenium test works

class SeleniumTest(unittest.TestCase):
    def testPage(self):
        self.browser.get("file:///home/hekra/qtwebdriver/b.qml")
        v = self.browser.execute_script("var v = ObjectNameUtils.findChild('button'); return v.objectName;")
        print "js result ", v
        v = self.browser.execute_script("var v = ObjectNameUtils.findChild('buttonText'); return v.font.pixelSize;")
        print "js result ", v
        v = self.browser.execute_script("var v = ObjectNameUtils.findChild('buttonText'); return v.parent.objectName;")
        print "js result ", v
@hekra01
Copy link
Contributor Author

hekra01 commented Jun 3, 2015

Qt4+qt5 suport: 5671ed3

@nazar-art
Copy link

nazar-art commented Nov 20, 2017

@hekra01 I tried to use this feature. However, it failed with Current view doesnt support this command

Here is more details: Current view doesnt support this command for Qml application with Qt WebDriver and Selenium

@hekra01
Copy link
Contributor Author

hekra01 commented Nov 21, 2017

Hi @nazar-art

I answered also in you post.
You need to select the QDeclarative view, otherwise the currently active window will be MainWidow, which cannot process JS
See explanations and examples here: https://github.com/cisco-open-source/qtwebdriver/wiki/Hybridity-And-View-Management

@nazar-art
Copy link

@hekra01 I watched this post earlier.
However, I did get how to combine this post and my typical situation with QDeclarative view.
Could you help with understandeng it?

@hekra01
Copy link
Contributor Author

hekra01 commented Nov 21, 2017

The source of your app is:

<?xml version="1.0" encoding="UTF-8"?>
<MainWindow elementId="2312dc5007f290f9bf4f3f92d3aa6884" className="MainWindow">
    <QRubberBand id="qt_rubberband" elementId="45050a91d64ad4cde3e3df8091813f54" className="QRubberBand"/>
    <QDeclarativeView elementId="3c4890eed00091c95bde9a653f59d22e" className="QDeclarativeView">
        <QWidget id="qt_scrollarea_hcontainer" elementId="ff075abbbeb5fe23501c7da3241def96" className="QWidget">
            <QScrollBar elementId="51188e66ef541bc0563bea5780cf8ed2" className="QScrollBar"/>
        </QWidget>
        <QWidget id="qt_scrollarea_vcontainer" elementId="3692bfb1340019907b7982f1ef2f821f" className="QWidget">
            <QScrollBar elementId="e76434466faf78d008ca5b096719e188" className="QScrollBar"/>
        </QWidget>
        <QWidget elementId="ac4c1e620945ad4784fbbcd3c60ae3f1" className="QWidget"/>
    </QDeclarativeView>
</MainWindow>

Using cap.setCapability("browserStartWindow", "*"); the webdriver will select the first window it finds.
In this case probably MainWindow. MainWindow cannot process
Check the Java code sample in https://github.com/cisco-open-source/qtwebdriver/wiki/Hybridity-And-View-Management#hybrid-uis
The selectWindow iterates the windows and switches to the one with required content type.

If you are using Option-1 then uou do not need the cap.setCapability("browserClass", "MyWebView"); and webCreator->RegisterViewClass<QDeclarativeView>("MyWebView");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants