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();
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();
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();
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!
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();