regularny
regularny

Reputation: 405

Selenium WebDriver dom locators workaround

Is there a way to do some workaround for Dom Locators when exporting testcase from Selenium IDE to java/junit/WebDriver?

These are not implemented yet (for about few years?)

I have an error:

// ERROR: Caught exception [Error: Dom locators are not implemented yet!]
// ERROR: Caught exception [Error: Dom locators are not implemented yet!]

My example dom locator:

document.findflight.servClass[2] 

<input type="radio" value="Coach" name="servClass" checked="">
<font face="Arial, Helvetica, sans-serif">
    Economy class
    <br>
    <input type="radio" value="Business" name="servClass">
    Business class
    <br>
    <input type="radio" value="First" name="servClass">
    First class
</font>

Upvotes: 1

Views: 920

Answers (3)

regularny
regularny

Reputation: 405

Actually i found my own solution thanks to this article: http://hiromia.blogspot.com/2015/10/how-to-handle-dom-in-selenium-webdriver.html

I used:

(WebElement) ((JavascriptExecutor) driver).executeScript("return " + el[0]);

Upvotes: 0

Florent B.
Florent B.

Reputation: 42518

Is there a way to do some workaround for Dom Locators when exporting test case from Selenium IDE to java/junit/WebDriver?

No there is no automatic convertion. You'll have to do it manually with either an xpath expression:

//*[@name='findflight']/*[@name='servClass'][2]

Or a CSS selector:

[name=findflight] > [name=servClass] > *:nth-child(2)

These are not implemented yet (for about few years?)

There is no point in implementing that feature since DOM locators are not reliable. A DOM locator is relative to the document, so any change in the structure of the page would break the test.

Upvotes: 1

Lora Borisova
Lora Borisova

Reputation: 21

You are right and there is still no direct export to "implemeneted locators" even for Selenium WebDriver (for instance). Due to that fact, you can workaround this by picking manually some direct locator strategy. Just check out all possible in the Selenium locator documentation here. Hope that helps.

Upvotes: 1

Related Questions