71522

selenium2 webdriver can't find the element newly created by javascript

Question:

Click on a link triggers an operation that creates new element. However, calling driver.findElement(By.id("")) after click returns does not find it.

I have tried the following code to wait for the element to appear.

wait.until(new ExpectedCondition() { public Boolean apply(WebDriver webDriver) { System.out.println("Searching ..."); return webDriver.findElement(By.id("itemType1")) != null; } });

But I still can't find it until timeout.

Answer1:

You can maybe use the element.isDisplayed()

Så do it like this:

WebElement jrnrText = driver.findElement(By.id("id")) if(jrnrText.isDisplayed()){ wait.until(presenceOfElementLocated(BY.id]("id"))) } Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) { return new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return driver.findElement(locator) } } }

Recommend

  • How can I force an AngluarJS form to realize required fields have been filled through DOM manipulati
  • Google Scripts for Sheets - onEdit and “source”
  • How to stop jQuery Mobile calling $.mobile.loading('hide') during changePage?
  • Can't map Ctrl + minus in Emacs in Mac OS X
  • Table field that holds row count from another table
  • Paramiko SSHException Channel Closed
  • iOS 9 custom transition - animationControllerForDismissedController not called
  • jQuery Mobile - Dialogs without changing hash
  • Parallel sieve of Eratosthenes - Java Multithreading
  • Is there any way to call saveCurrentTurnWithMatchData without sending a push notification?
  • Multiple producers single consumer locking schema
  • Code in Job's Script Block after Start-Process Does not Execute
  • How can I extract results of aggregate queries in slick?
  • OOP Javascript - Is “get property” method necessary?
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • PHP - How to update data to MySQL when click a radio button
  • Fill an image in a square container while keeping aspect ratio
  • jquery mobile loadPage not working
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Data Validation Drop Down Box Arrow Disappearing
  • How to delete a row from a dynamic generate table using jquery?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • How do you join a server to an Active Directory (domain)?
  • JTable with a ScrollPane misbehaving
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How to stop GridView from loading again when I press back button?
  • How can I remove ASP.NET Designer.cs files?
  • Bitwise OR returns boolean when one of operands is nil
  • python draw pie shapes with colour filled
  • unknown Exception android
  • Is there any way to bind data to data.frame by some index?
  • Reading document lines to the user (python)
  • How can i traverse a binary tree from right to left in java?
  • failed to connect to specific WiFi in android programmatically
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?