Element created using XSLT templates not visible to Selenium

The problem is that when I try to set the value for input, selenium returns the following error: RuntimeError: the element is not currently visible and therefore cannot interact with

Be that as it may, the entrance is fully visible. In this test, I use Firefox because it is the browser in which the application is loaded correctly.

I cannot change the application code, and the application has a lot of legacy code, but I recreated the simplest example where you can see the problem.

Do you know a workaround without changing application code?

I am using webdriverio:

this.browser
    .url('http://localhost/main.xml')
    .setValue('[name=inputId]', 'aaaaaaaa')
    .close()
    .then(callback)

main.xml:

<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="main.xsl" ?>
<CONTEXTO></CONTEXTO>

main.xsl:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="iso-8859-1"/>

    <xsl:include href="helper.xsl"/>

    <xsl:template match="CONTEXTO">
        <html>
            <head>
                <title>Test main</title>
                <style>
                    * { margin:0; }
                    form { position: absolute; }
                    input { border: 1px black solid; }
                </style>
            </head>
            <body>
                <form name="" action="" method="POST">
                    <label for="inputId">inputId
                        <input type="text" name="inputId" id="inputId" value="" />
                    </label>
                </form>
            </body>
        </html>

    </xsl:template>
</xsl:stylesheet>

Content helper.xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <script></script>
        <xsl:apply-templates select="CONTEXTO"/>
    </xsl:template>
</xsl:stylesheet>
+4
source share
3

, Selenium XML-, -, HTML-. , SendKeys. , , .

find_element_by_name find_element_by_id XPath webdriver.io. , , root node . , , Selenium XML DOM ( ), DOM, XSLT.

0

:

.waitForExist('[name=inputId]', 1000)
.setValue('[name=inputId]', 'aaaaaaaa')
0

, XSL HTML. / script CONTEXTO, , :

<script></script>
<html>....</html>

, HTML.

- firefox TransformiIX HTML text, -, transformiix:result. (. ).

, , getPageSource() webdriver . , :

<transformiix:result>
    <script></script>
    <html>....</html>
</transformiix:result>

webdriver .

- XSLT. ( ), script webdriver executeScript ( ).

document.getRootNode().replaceChild(document.getElementsByTagName('html')[0], document.getElementsByTagName('transformiix:result')[0])

node transformiix:result HTML.

, , helper.xsl, script .


: XSL, firefox:

//Execute in a firefox inspect console
var p = new XSLTProcessor();

var toTransform = document.implementation.createDocument(null, "CONTEXTO");

var parser = new DOMParser();
var xmlString = `<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="iso-8859-1"/>
    <xsl:template match="/">
        <script></script>
        <xsl:apply-templates select="CONTEXTO"/>
    </xsl:template>
    <xsl:template match="CONTEXTO">
        <html>
            <body>
                Hello
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>
`;

p.importStylesheet(parser.parseFromString(xmlString, "text/xml"));

var doc = p.transformToDocument(toTransform);
console.log(doc.getRootNode().children[0].outerHTML);
0

Source: https://habr.com/ru/post/1607507/


All Articles