Selenium unique element not returned by span text










1















On a web page, this element is the only one containing the exact text 'Volgende stap':



<span class="b-button--label ng-binding ng-scope" ng-if="arrowDirection === 'right'">Volgende stap</span>


But when I try to select (a list of) the elements containing these words using xpath:



driver.find_elements_by_xpath("//span[contains(text(),'Volgende')]")
driver.find_elements_by_xpath("//span[.='Volgende stap']")
driver.find_elements_by_xpath("//span[text()='Volgende stap']")


I keep getting an empty list (or element not found in case of find_element instead of find_elements).



This is the script leading to the html page I'm working on:



from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait

driver = webdriver.Chrome()
driver.get("https://www.greetz.nl/kaarten/verjaardag/man")
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Kaart bewerken']"))).click()









share|improve this question
























  • so if I go to that page and manually click on /kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148 and search for Volgende on either visible page, or page source, nothing comes up.

    – Kiril S.
    Nov 13 '18 at 23:36















1















On a web page, this element is the only one containing the exact text 'Volgende stap':



<span class="b-button--label ng-binding ng-scope" ng-if="arrowDirection === 'right'">Volgende stap</span>


But when I try to select (a list of) the elements containing these words using xpath:



driver.find_elements_by_xpath("//span[contains(text(),'Volgende')]")
driver.find_elements_by_xpath("//span[.='Volgende stap']")
driver.find_elements_by_xpath("//span[text()='Volgende stap']")


I keep getting an empty list (or element not found in case of find_element instead of find_elements).



This is the script leading to the html page I'm working on:



from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait

driver = webdriver.Chrome()
driver.get("https://www.greetz.nl/kaarten/verjaardag/man")
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Kaart bewerken']"))).click()









share|improve this question
























  • so if I go to that page and manually click on /kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148 and search for Volgende on either visible page, or page source, nothing comes up.

    – Kiril S.
    Nov 13 '18 at 23:36













1












1








1








On a web page, this element is the only one containing the exact text 'Volgende stap':



<span class="b-button--label ng-binding ng-scope" ng-if="arrowDirection === 'right'">Volgende stap</span>


But when I try to select (a list of) the elements containing these words using xpath:



driver.find_elements_by_xpath("//span[contains(text(),'Volgende')]")
driver.find_elements_by_xpath("//span[.='Volgende stap']")
driver.find_elements_by_xpath("//span[text()='Volgende stap']")


I keep getting an empty list (or element not found in case of find_element instead of find_elements).



This is the script leading to the html page I'm working on:



from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait

driver = webdriver.Chrome()
driver.get("https://www.greetz.nl/kaarten/verjaardag/man")
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Kaart bewerken']"))).click()









share|improve this question
















On a web page, this element is the only one containing the exact text 'Volgende stap':



<span class="b-button--label ng-binding ng-scope" ng-if="arrowDirection === 'right'">Volgende stap</span>


But when I try to select (a list of) the elements containing these words using xpath:



driver.find_elements_by_xpath("//span[contains(text(),'Volgende')]")
driver.find_elements_by_xpath("//span[.='Volgende stap']")
driver.find_elements_by_xpath("//span[text()='Volgende stap']")


I keep getting an empty list (or element not found in case of find_element instead of find_elements).



This is the script leading to the html page I'm working on:



from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait

driver = webdriver.Chrome()
driver.get("https://www.greetz.nl/kaarten/verjaardag/man")
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Kaart bewerken']"))).click()






python selenium xpath css-selectors webdriverwait






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 7:00









DebanjanB

41.1k83878




41.1k83878










asked Nov 13 '18 at 22:02









DaRealDaReal

139216




139216












  • so if I go to that page and manually click on /kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148 and search for Volgende on either visible page, or page source, nothing comes up.

    – Kiril S.
    Nov 13 '18 at 23:36

















  • so if I go to that page and manually click on /kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148 and search for Volgende on either visible page, or page source, nothing comes up.

    – Kiril S.
    Nov 13 '18 at 23:36
















so if I go to that page and manually click on /kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148 and search for Volgende on either visible page, or page source, nothing comes up.

– Kiril S.
Nov 13 '18 at 23:36





so if I go to that page and manually click on /kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148 and search for Volgende on either visible page, or page source, nothing comes up.

– Kiril S.
Nov 13 '18 at 23:36












2 Answers
2






active

oldest

votes


















1














As per the HTML the desired element with text as Volgende stap is within an <iframe> so you have to:



  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.


  • You can use the following solution:




    • Using CSS_SELECTOR:



      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()



    • Using XPATH:



      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()



Note : You have to add the following imports :



from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC


Here you can find a relevant discussion on Ways to deal with #document under iframe






share|improve this answer























  • I see, so it was because of an Iframe. Thanks for the explanation and link to more information.

    – DaReal
    Nov 14 '18 at 18:56


















2














It's in an iframe. Switch to it first, then try and find via text:



frame = driver.find_element_by_css_selector('frame.personalize--frame')
driver.switch_to.frame(frame)





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290184%2fselenium-unique-element-not-returned-by-span-text%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    As per the HTML the desired element with text as Volgende stap is within an <iframe> so you have to:



    • Induce WebDriverWait for the desired frame to be available and switch to it.

    • Induce WebDriverWait for the desired element to be clickable.


    • You can use the following solution:




      • Using CSS_SELECTOR:



        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()



      • Using XPATH:



        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()



    Note : You have to add the following imports :



    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC


    Here you can find a relevant discussion on Ways to deal with #document under iframe






    share|improve this answer























    • I see, so it was because of an Iframe. Thanks for the explanation and link to more information.

      – DaReal
      Nov 14 '18 at 18:56















    1














    As per the HTML the desired element with text as Volgende stap is within an <iframe> so you have to:



    • Induce WebDriverWait for the desired frame to be available and switch to it.

    • Induce WebDriverWait for the desired element to be clickable.


    • You can use the following solution:




      • Using CSS_SELECTOR:



        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()



      • Using XPATH:



        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()



    Note : You have to add the following imports :



    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC


    Here you can find a relevant discussion on Ways to deal with #document under iframe






    share|improve this answer























    • I see, so it was because of an Iframe. Thanks for the explanation and link to more information.

      – DaReal
      Nov 14 '18 at 18:56













    1












    1








    1







    As per the HTML the desired element with text as Volgende stap is within an <iframe> so you have to:



    • Induce WebDriverWait for the desired frame to be available and switch to it.

    • Induce WebDriverWait for the desired element to be clickable.


    • You can use the following solution:




      • Using CSS_SELECTOR:



        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()



      • Using XPATH:



        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()



    Note : You have to add the following imports :



    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC


    Here you can find a relevant discussion on Ways to deal with #document under iframe






    share|improve this answer













    As per the HTML the desired element with text as Volgende stap is within an <iframe> so you have to:



    • Induce WebDriverWait for the desired frame to be available and switch to it.

    • Induce WebDriverWait for the desired element to be clickable.


    • You can use the following solution:




      • Using CSS_SELECTOR:



        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.personalize--frame[src='//www.greetz.nl/editor/desktop.html']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.b-button--label.ng-binding.ng-scope[ng-if*='right']"))).click()



      • Using XPATH:



        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='personalize--frame' and @src='//www.greetz.nl/editor/desktop.html']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='b-button--label ng-binding ng-scope' and contains(text(),'Volgende')]"))).click()



    Note : You have to add the following imports :



    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC


    Here you can find a relevant discussion on Ways to deal with #document under iframe







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 14 '18 at 7:06









    DebanjanBDebanjanB

    41.1k83878




    41.1k83878












    • I see, so it was because of an Iframe. Thanks for the explanation and link to more information.

      – DaReal
      Nov 14 '18 at 18:56

















    • I see, so it was because of an Iframe. Thanks for the explanation and link to more information.

      – DaReal
      Nov 14 '18 at 18:56
















    I see, so it was because of an Iframe. Thanks for the explanation and link to more information.

    – DaReal
    Nov 14 '18 at 18:56





    I see, so it was because of an Iframe. Thanks for the explanation and link to more information.

    – DaReal
    Nov 14 '18 at 18:56













    2














    It's in an iframe. Switch to it first, then try and find via text:



    frame = driver.find_element_by_css_selector('frame.personalize--frame')
    driver.switch_to.frame(frame)





    share|improve this answer



























      2














      It's in an iframe. Switch to it first, then try and find via text:



      frame = driver.find_element_by_css_selector('frame.personalize--frame')
      driver.switch_to.frame(frame)





      share|improve this answer

























        2












        2








        2







        It's in an iframe. Switch to it first, then try and find via text:



        frame = driver.find_element_by_css_selector('frame.personalize--frame')
        driver.switch_to.frame(frame)





        share|improve this answer













        It's in an iframe. Switch to it first, then try and find via text:



        frame = driver.find_element_by_css_selector('frame.personalize--frame')
        driver.switch_to.frame(frame)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 1:23









        Lucas TierneyLucas Tierney

        1,64288




        1,64288



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290184%2fselenium-unique-element-not-returned-by-span-text%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3