如何在CK编辑器中单击链接图标

时间:2019-03-28 10:33:52

标签: selenium selenium-webdriver xpath css-selectors webdriverwait

当我最初在ck编辑器中单击链接图标时,它可以工作,但是当我重新运行代码时,它不是在ck编辑器中单击链接图标。

这是我最初使用的命令:

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

enter image description here

3 个答案:

答案 0 :(得分:1)

使用WebDriverWait处理动态元素。

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

答案 1 :(得分:0)

@akshay-patil所述,请使用a标签。原因是<a>标签是链接本身……而不是跨度!

您应该使用:

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

希望这会有所帮助!

答案 2 :(得分:0)

所需元素是启用了JavaScript的元素,因此对元素click()进行CSS_SELECTOR诱使 WebDriverWait 以便使元素可点击并且您可以使用以下任一Locator Strategies

  • 使用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();

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

    Invoke-Command                      `
        -Session        $workingSession `
        -ScriptBlock    {
            get-service *spool* -ComputerName server01
        }
    
相关问题