Unable to find ::before css selector element in selenium webdriver

前端 未结 3 1390
野趣味
野趣味 2021-02-15 18:51

I want to test for checkbox checked or unchecked condition.

This is the html code for checkbox checked

<
相关标签:
3条回答
  • 2021-02-15 19:23

    In my case, I have removed the pseudo-element ::before from the CSS selector as seen below and it works

    Instead of:

    Actions action = new Actions(driver);
    action.moveToElement(driver.findElement(By.cssSelector("span.check::before"))).build().perform();
    

    I gave:

    Actions action = new Actions(driver);
    action.moveToElement(driver.findElement(By.cssSelector("span.check"))).build().perform();
    

    Using pseudo-elements in the selector is actually not supposed to work as mentioned here and here.

    0 讨论(0)
  • 2021-02-15 19:23

    I'm not sure of your exact html as the comment mentions there is no ::after in your example html. Based on your description this seems similar to the below, but not sure if that is what your exact situation is.

    I have utilized the mouse move and then wait for the element that displays the modified css/class. The mouse would move and hover to the first element and then wait for the second to appear on the screen. This works similarly for click and then wait for element to appear.

    Hover code example - needs to match your code language and structure...

    [Actions Instance goes here].MoveToElement([IWebElementGoesHere]).Perform();
    

    you can also just do

    [Actions Instance].Click([IWebElementGoesHere]).Perform();
    

    Reference for this library: https://code.google.com/p/selenium/wiki/AdvancedUserInteractions

    0 讨论(0)
  • 2021-02-15 19:23

    I have faced similar issue with pseudo css selectors (::before alike), I have overcome the issue using "Actions" class of selenium java.

    Actions action = new Actions(driver);
    action.moveToElement(driver.findElement(By.cssSelector("button[id$='save-button']"))).build().perform();
    

    Hope it helps.

    Thanks, Sampath

    0 讨论(0)
提交回复
热议问题