0

I'd like to do things like this;

elem1 = document.getElementById(id1);
elem1.click()
// The page has been changed
elem2 = document.getElementById(id2);
elem2.click()

My problem is, if the second 'getElementById(id2)' is called before the HTML of document.documentElement completes its change, it sometimes fails to get elem2 because there is no HTML element that has id2. (Every javascript sentence in the above code is sent from 3rd party like Selenium Server, and there is a javascript loop that gets the sentence and runs it one by one. You can think the loop as a thing like Selenium Core)

I'm trying to write a tool like Selenium or Watir. So I can't use those tools. I think Selenium or Watir has a way to send the second command after it waits until the page has been completely changed as the result of the first command. I tried events like window.onwebkittransitionend because I'm trying this on Webkit, but it did not work.

I don't think promise or async can solve this problem, because it needs more than enforcing sequences. It needs to verify if the second page is fully loaded, because the second command can be the others like fetching the information of rendered images rather than just click.

Is there any event or a way to check if page change is completed? Oh, and I can't use jQuery unfortunately. I need to do it with plain Javascript.

Thanks for reading my question.

Chanwoo
  • 13
  • 2
  • do you have any asynchronous calls happening when `elem1.click()` is fired like making a ajax call – Arun P Johny Jul 08 '13 at 08:47
  • Can you share what is happening when `elem1.click()` is called – Arun P Johny Jul 08 '13 at 08:47
  • @ArunPJohny I'm not sure async calls can solve this problem, as I wrote in the question. I need to make the second click called after document.documentElement.outerHtml is changed by the first click and an element that has id2 appears. Async calls does not guarantee that the second click is called after the element that has id2 appears. – Chanwoo Jul 08 '13 at 12:43
  • @ArunPJohny If elem1 is clicked, then HTML of the page is changed, and an element that has id2 appears on the document.documentElement.outerHTML – Chanwoo Jul 08 '13 at 12:45
  • Possible duplicate of http://stackoverflow.com/questions/3219758/detect-changes-in-the-dom – André Dion Jul 11 '13 at 14:08

0 Answers0