0

I trying to locate elemnts in this page and put it in Objects (DomElement) to making some tests of it, the problem is with elemnt reg-error-yid it is a inner-div inside div yid-field-suggestion, I tried to getElementById, byName, byXPath, and getFirstByXPath it's all not working , also I tried to change webClient with WebDriver and use driver.findElement(By.className("oneid-error-message")) it's also not working

the elemnt of registered message

<div id="reg-error-yid" class="oneid-error-message" data-error="messages.IDENTIFIER_EXISTS" role="alert">A Yahoo account already exists with this email address. <a href="https://login.yahoo.com/?intl=xa&amp;lang=en-JO&amp;src=ym&amp;.intl=xa&amp;specId=yidReg&amp;.done=https%3A%2F%2Fmail.yahoo.com&amp;nr=1&amp;step=2&amp;.crumb=qP.UnkGzfkR&amp;login=abtallaldigital">Sign in</a>.</div>

my code

final HtmlPage page1 = webClient.getPage("https://login.yahoo.com/account/create?specId=yidReg&lang=en-JO&src=ym&done=https%3A%2F%2Fmail.yahoo.com&display=login&intl=xa");

             final DomElement firstName = page1.getElementById("usernamereg-firstName");
             final DomElement emailAddress = page1.getElementById("usernamereg-yid");
             final DomElement takenMsg = page1.getElementById("reg-error-yid");
Dr Mido
  • 2,414
  • 4
  • 32
  • 72

1 Answers1

1

I am not sure about your need. I can't comment here.

But if you are trying to parse the document you can use Jsoup for parsing the document.

The select is more useful and easy as compared to getElementById, byName, byXPath.

org.jsoup.nodes.Document doc = Jsoup.connect("https://login.yahoo.com/account/create?specId=yidReg&lang=en-JO&src=ym&done=https%3A%2F%2Fmail.yahoo.com&display=login&intl=xa").get();
org.jsoup.select.Elements takenMsgs = doc.select("div[id=reg-error-yid]");
org.jsoup.select.Element takenMsgFirst = doc.select("div[id=reg-error-yid]").first;

See if you can convert org.jsoup.select.Elements to com.gargoylesoftware.htmlunit.html.DomElement

r_D
  • 578
  • 1
  • 7
  • 16
  • thank you, see this question [link](http://stackoverflow.com/questions/43901997/htmlunit-always-gives-multiple-javascript-exceptions-after-running-the-project) to be related – Dr Mido May 12 '17 at 14:22