-1

When I click the link icon in ck editor initially it worked, but when I re-run the code, it's not clicking the link icon in the ck editor.

This is the command I used initially:

driver.findElement(By.xpath("//*[@id='cke_29']/span[1]")).click();

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
User2080
  • 69
  • 6

3 Answers3

1

Use WebDriverWait to handle dynamic element.

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[starts-with(@id,'cke_')][@class='cke_button cke_button__link cke_button_off']"))).click();
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

As @akshay-patil commented use the a tag. The reason is that the <a> tag is the link itself... not the span!

You should use:

driver.findElement(By.xpath("//*[@id='cke_29']")).click();

Hope this helps!

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
0

The desired element is a JavaScript enabled element so to click() on the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.cke_button.cke_button__link.cke_button_off[id^='cke_'][title^='Link']>span.cke_button_icon.cke_button__link_icon"))).click();
    
  • Using XPATH:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='cke_button cke_button__link cke_button_off' and starts-with(@id,'cke_')][starts-with(@title,'Link')]/span[@class='cke_button_icon cke_button__link_icon']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352