Grabbing text from a list with no ID or class using Selenium










1















I don't understand why the list I'm trying to extract the text from is returning blanks when I'm definitely using the correct Xpath. Here is my code:



driver = webdriver.Firefox()
driver.get("https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001")
betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li[1]")])
print(betweenLugs.text)


This should grab the first list item and measurement



Between lugs: 20 mm 


I have also tried other methods, but the fact that Xpath doesn't pick it up tells me something is wrong and it doesn't matter how I do it, I won't be able to extract the text inside the lists. Does anyone know what am I doing wrong? This is the first time I've ran into this problem.










share|improve this question
























  • I think the line should be: betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li")])[0]

    – Alichino
    Nov 13 '18 at 12:45












  • Every list item within the unordered list in regards to the technical information, so that would be everything from "Between Lugs" all the way down to "Water Resistant" and all the appropriate values that pertain to the headings.

    – LRBrady
    Nov 13 '18 at 12:48












  • @Alichino that unfortunately just prints blank; no error or content. I was having that issue as well when trying different things. I'm not sure why.

    – LRBrady
    Nov 13 '18 at 12:52















1















I don't understand why the list I'm trying to extract the text from is returning blanks when I'm definitely using the correct Xpath. Here is my code:



driver = webdriver.Firefox()
driver.get("https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001")
betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li[1]")])
print(betweenLugs.text)


This should grab the first list item and measurement



Between lugs: 20 mm 


I have also tried other methods, but the fact that Xpath doesn't pick it up tells me something is wrong and it doesn't matter how I do it, I won't be able to extract the text inside the lists. Does anyone know what am I doing wrong? This is the first time I've ran into this problem.










share|improve this question
























  • I think the line should be: betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li")])[0]

    – Alichino
    Nov 13 '18 at 12:45












  • Every list item within the unordered list in regards to the technical information, so that would be everything from "Between Lugs" all the way down to "Water Resistant" and all the appropriate values that pertain to the headings.

    – LRBrady
    Nov 13 '18 at 12:48












  • @Alichino that unfortunately just prints blank; no error or content. I was having that issue as well when trying different things. I'm not sure why.

    – LRBrady
    Nov 13 '18 at 12:52













1












1








1








I don't understand why the list I'm trying to extract the text from is returning blanks when I'm definitely using the correct Xpath. Here is my code:



driver = webdriver.Firefox()
driver.get("https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001")
betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li[1]")])
print(betweenLugs.text)


This should grab the first list item and measurement



Between lugs: 20 mm 


I have also tried other methods, but the fact that Xpath doesn't pick it up tells me something is wrong and it doesn't matter how I do it, I won't be able to extract the text inside the lists. Does anyone know what am I doing wrong? This is the first time I've ran into this problem.










share|improve this question
















I don't understand why the list I'm trying to extract the text from is returning blanks when I'm definitely using the correct Xpath. Here is my code:



driver = webdriver.Firefox()
driver.get("https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001")
betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li[1]")])
print(betweenLugs.text)


This should grab the first list item and measurement



Between lugs: 20 mm 


I have also tried other methods, but the fact that Xpath doesn't pick it up tells me something is wrong and it doesn't matter how I do it, I won't be able to extract the text inside the lists. Does anyone know what am I doing wrong? This is the first time I've ran into this problem.







python python-3.x selenium selenium-webdriver web-scraping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 12:30









Guy

19.4k72251




19.4k72251










asked Nov 13 '18 at 12:20









LRBradyLRBrady

398




398












  • I think the line should be: betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li")])[0]

    – Alichino
    Nov 13 '18 at 12:45












  • Every list item within the unordered list in regards to the technical information, so that would be everything from "Between Lugs" all the way down to "Water Resistant" and all the appropriate values that pertain to the headings.

    – LRBrady
    Nov 13 '18 at 12:48












  • @Alichino that unfortunately just prints blank; no error or content. I was having that issue as well when trying different things. I'm not sure why.

    – LRBrady
    Nov 13 '18 at 12:52

















  • I think the line should be: betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li")])[0]

    – Alichino
    Nov 13 '18 at 12:45












  • Every list item within the unordered list in regards to the technical information, so that would be everything from "Between Lugs" all the way down to "Water Resistant" and all the appropriate values that pertain to the headings.

    – LRBrady
    Nov 13 '18 at 12:48












  • @Alichino that unfortunately just prints blank; no error or content. I was having that issue as well when trying different things. I'm not sure why.

    – LRBrady
    Nov 13 '18 at 12:52
















I think the line should be: betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li")])[0]

– Alichino
Nov 13 '18 at 12:45






I think the line should be: betweenLugs = driver.find_elements(By.XPATH, "/html/body/div[2]/main/div[3]/div/div/div[2]/div/div[2]/div[3]/div/ul/li")])[0]

– Alichino
Nov 13 '18 at 12:45














Every list item within the unordered list in regards to the technical information, so that would be everything from "Between Lugs" all the way down to "Water Resistant" and all the appropriate values that pertain to the headings.

– LRBrady
Nov 13 '18 at 12:48






Every list item within the unordered list in regards to the technical information, so that would be everything from "Between Lugs" all the way down to "Water Resistant" and all the appropriate values that pertain to the headings.

– LRBrady
Nov 13 '18 at 12:48














@Alichino that unfortunately just prints blank; no error or content. I was having that issue as well when trying different things. I'm not sure why.

– LRBrady
Nov 13 '18 at 12:52





@Alichino that unfortunately just prints blank; no error or content. I was having that issue as well when trying different things. I'm not sure why.

– LRBrady
Nov 13 '18 at 12:52












5 Answers
5






active

oldest

votes


















1














OK, try this and see if it solves the problem:



between_lugs = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]").get_attribute("innerHTML")
between_lugs_value = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]/../span").get_attribute("innerHTML")

final_text = between_lugs + " " + between_lugs_value





share|improve this answer























  • Thank you but unfortunately this returns: "selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[contains(text(), 'Between lugs')]"

    – LRBrady
    Nov 13 '18 at 12:55











  • It works for me in the python interpreter... Please copy the URL you are on again :)

    – Alichino
    Nov 13 '18 at 13:00











  • I see, I think it's because my browser automatically takes it to the German site. The link I gave was to the US so that's probably why. My fault. The URL is here: omegawatches.com/de/… but I think if I just change a few things accordingly it should work.

    – LRBrady
    Nov 13 '18 at 13:02











  • I think it should :) Or change the text in CONTAINS to "Zwischen den Bandanstößen" :D PS. Also, the value has a space after the number in the form of   -- you can do between_lugs_value = between_lugs_value.replace(" "," ")

    – Alichino
    Nov 13 '18 at 13:03












  • Yep, this gets it pretty much how I need it, just need to strip a few things away but otherwise looks good. Thank you

    – LRBrady
    Nov 13 '18 at 13:09


















3














The xpath is wrong. It fails in /div[2], it doesn't match anything. This is an example why you shouldn't use absolute path.



The section has id attribute, use it



betweenLugs = driver.find_elements(By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")[0]


You might also want to add some wait for the loading



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

betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")))





share|improve this answer

























  • That's a better idea, I will try and use your suggestion, however when indexing with [0], I get the error "list index is out of range."

    – LRBrady
    Nov 13 '18 at 12:35







  • 1





    @LRBrady It might be timing issue, I updated my answer.

    – Guy
    Nov 13 '18 at 12:38











  • I appreciate the edit, I'm not sure it's a timing issue because even with the edit, selenium is just timing out and not finding anything. I'll continue with your suggestion and try to make some changes.

    – LRBrady
    Nov 13 '18 at 12:44






  • 1





    @LRBrady Try to maximize the window driver.maximize_window(), call it after the driver initialization.

    – Guy
    Nov 13 '18 at 13:02






  • 1





    @Guy It still seems to time out with that, this text is tricky to get a hold of but I think the other answer has given the best results. Thanks for your help.

    – LRBrady
    Nov 13 '18 at 13:12


















2














That page already has jQuery on it so you can just:



driver.execute_script("return jQuery('li:contains(Between lugs)').text().trim().replace(/s+/g, ' ')")


You can fiddle with selectors in the chrome selectors, it makes it much easier.






share|improve this answer























  • Very interesting. Thanks.

    – QHarr
    Nov 14 '18 at 8:11


















1














Another simpler approach might be the following one:



from contextlib import closing
from selenium import webdriver
from selenium.webdriver.support import ui

url = "https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001"

with closing(webdriver.Chrome()) as wd:
wait = ui.WebDriverWait(wd, 10)
wd.get(url)
item = wait.until(lambda wd: wd.find_element_by_xpath("//*[contains(@class,'technical-data')]//li")).get_attribute('textContent')
print(' '.join(item.split()))


Output:



Between lugs: 20 mm





share|improve this answer























  • Do I see a context manager? ;-) +

    – QHarr
    Nov 13 '18 at 19:20






  • 1





    I find it very handy when It comes to open and quit the browser in a single shot @QHarr. Thanks.

    – SIM
    Nov 13 '18 at 19:33


















0














Using a scroll down and a wait with a css selector to target the parent li



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

driver = webdriver.Chrome() #Firefox()
driver.get("https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001")
driver.execute_script("window.scrollTo(0, 2000)")
betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, "#product-info-data-5beaf5497d916 > ul > li:nth-child(1)")))

print(betweenLugs.text)





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%2f53280886%2fgrabbing-text-from-a-list-with-no-id-or-class-using-selenium%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    OK, try this and see if it solves the problem:



    between_lugs = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]").get_attribute("innerHTML")
    between_lugs_value = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]/../span").get_attribute("innerHTML")

    final_text = between_lugs + " " + between_lugs_value





    share|improve this answer























    • Thank you but unfortunately this returns: "selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[contains(text(), 'Between lugs')]"

      – LRBrady
      Nov 13 '18 at 12:55











    • It works for me in the python interpreter... Please copy the URL you are on again :)

      – Alichino
      Nov 13 '18 at 13:00











    • I see, I think it's because my browser automatically takes it to the German site. The link I gave was to the US so that's probably why. My fault. The URL is here: omegawatches.com/de/… but I think if I just change a few things accordingly it should work.

      – LRBrady
      Nov 13 '18 at 13:02











    • I think it should :) Or change the text in CONTAINS to "Zwischen den Bandanstößen" :D PS. Also, the value has a space after the number in the form of   -- you can do between_lugs_value = between_lugs_value.replace(" "," ")

      – Alichino
      Nov 13 '18 at 13:03












    • Yep, this gets it pretty much how I need it, just need to strip a few things away but otherwise looks good. Thank you

      – LRBrady
      Nov 13 '18 at 13:09















    1














    OK, try this and see if it solves the problem:



    between_lugs = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]").get_attribute("innerHTML")
    between_lugs_value = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]/../span").get_attribute("innerHTML")

    final_text = between_lugs + " " + between_lugs_value





    share|improve this answer























    • Thank you but unfortunately this returns: "selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[contains(text(), 'Between lugs')]"

      – LRBrady
      Nov 13 '18 at 12:55











    • It works for me in the python interpreter... Please copy the URL you are on again :)

      – Alichino
      Nov 13 '18 at 13:00











    • I see, I think it's because my browser automatically takes it to the German site. The link I gave was to the US so that's probably why. My fault. The URL is here: omegawatches.com/de/… but I think if I just change a few things accordingly it should work.

      – LRBrady
      Nov 13 '18 at 13:02











    • I think it should :) Or change the text in CONTAINS to "Zwischen den Bandanstößen" :D PS. Also, the value has a space after the number in the form of   -- you can do between_lugs_value = between_lugs_value.replace(" "," ")

      – Alichino
      Nov 13 '18 at 13:03












    • Yep, this gets it pretty much how I need it, just need to strip a few things away but otherwise looks good. Thank you

      – LRBrady
      Nov 13 '18 at 13:09













    1












    1








    1







    OK, try this and see if it solves the problem:



    between_lugs = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]").get_attribute("innerHTML")
    between_lugs_value = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]/../span").get_attribute("innerHTML")

    final_text = between_lugs + " " + between_lugs_value





    share|improve this answer













    OK, try this and see if it solves the problem:



    between_lugs = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]").get_attribute("innerHTML")
    between_lugs_value = driver.find_element_by_xpath("//*[contains(text(), 'Between lugs')]/../span").get_attribute("innerHTML")

    final_text = between_lugs + " " + between_lugs_value






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 12:51









    AlichinoAlichino

    8031818




    8031818












    • Thank you but unfortunately this returns: "selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[contains(text(), 'Between lugs')]"

      – LRBrady
      Nov 13 '18 at 12:55











    • It works for me in the python interpreter... Please copy the URL you are on again :)

      – Alichino
      Nov 13 '18 at 13:00











    • I see, I think it's because my browser automatically takes it to the German site. The link I gave was to the US so that's probably why. My fault. The URL is here: omegawatches.com/de/… but I think if I just change a few things accordingly it should work.

      – LRBrady
      Nov 13 '18 at 13:02











    • I think it should :) Or change the text in CONTAINS to "Zwischen den Bandanstößen" :D PS. Also, the value has a space after the number in the form of   -- you can do between_lugs_value = between_lugs_value.replace(" "," ")

      – Alichino
      Nov 13 '18 at 13:03












    • Yep, this gets it pretty much how I need it, just need to strip a few things away but otherwise looks good. Thank you

      – LRBrady
      Nov 13 '18 at 13:09

















    • Thank you but unfortunately this returns: "selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[contains(text(), 'Between lugs')]"

      – LRBrady
      Nov 13 '18 at 12:55











    • It works for me in the python interpreter... Please copy the URL you are on again :)

      – Alichino
      Nov 13 '18 at 13:00











    • I see, I think it's because my browser automatically takes it to the German site. The link I gave was to the US so that's probably why. My fault. The URL is here: omegawatches.com/de/… but I think if I just change a few things accordingly it should work.

      – LRBrady
      Nov 13 '18 at 13:02











    • I think it should :) Or change the text in CONTAINS to "Zwischen den Bandanstößen" :D PS. Also, the value has a space after the number in the form of   -- you can do between_lugs_value = between_lugs_value.replace(" "," ")

      – Alichino
      Nov 13 '18 at 13:03












    • Yep, this gets it pretty much how I need it, just need to strip a few things away but otherwise looks good. Thank you

      – LRBrady
      Nov 13 '18 at 13:09
















    Thank you but unfortunately this returns: "selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[contains(text(), 'Between lugs')]"

    – LRBrady
    Nov 13 '18 at 12:55





    Thank you but unfortunately this returns: "selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[contains(text(), 'Between lugs')]"

    – LRBrady
    Nov 13 '18 at 12:55













    It works for me in the python interpreter... Please copy the URL you are on again :)

    – Alichino
    Nov 13 '18 at 13:00





    It works for me in the python interpreter... Please copy the URL you are on again :)

    – Alichino
    Nov 13 '18 at 13:00













    I see, I think it's because my browser automatically takes it to the German site. The link I gave was to the US so that's probably why. My fault. The URL is here: omegawatches.com/de/… but I think if I just change a few things accordingly it should work.

    – LRBrady
    Nov 13 '18 at 13:02





    I see, I think it's because my browser automatically takes it to the German site. The link I gave was to the US so that's probably why. My fault. The URL is here: omegawatches.com/de/… but I think if I just change a few things accordingly it should work.

    – LRBrady
    Nov 13 '18 at 13:02













    I think it should :) Or change the text in CONTAINS to "Zwischen den Bandanstößen" :D PS. Also, the value has a space after the number in the form of   -- you can do between_lugs_value = between_lugs_value.replace(" "," ")

    – Alichino
    Nov 13 '18 at 13:03






    I think it should :) Or change the text in CONTAINS to "Zwischen den Bandanstößen" :D PS. Also, the value has a space after the number in the form of   -- you can do between_lugs_value = between_lugs_value.replace(" "," ")

    – Alichino
    Nov 13 '18 at 13:03














    Yep, this gets it pretty much how I need it, just need to strip a few things away but otherwise looks good. Thank you

    – LRBrady
    Nov 13 '18 at 13:09





    Yep, this gets it pretty much how I need it, just need to strip a few things away but otherwise looks good. Thank you

    – LRBrady
    Nov 13 '18 at 13:09













    3














    The xpath is wrong. It fails in /div[2], it doesn't match anything. This is an example why you shouldn't use absolute path.



    The section has id attribute, use it



    betweenLugs = driver.find_elements(By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")[0]


    You might also want to add some wait for the loading



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

    betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")))





    share|improve this answer

























    • That's a better idea, I will try and use your suggestion, however when indexing with [0], I get the error "list index is out of range."

      – LRBrady
      Nov 13 '18 at 12:35







    • 1





      @LRBrady It might be timing issue, I updated my answer.

      – Guy
      Nov 13 '18 at 12:38











    • I appreciate the edit, I'm not sure it's a timing issue because even with the edit, selenium is just timing out and not finding anything. I'll continue with your suggestion and try to make some changes.

      – LRBrady
      Nov 13 '18 at 12:44






    • 1





      @LRBrady Try to maximize the window driver.maximize_window(), call it after the driver initialization.

      – Guy
      Nov 13 '18 at 13:02






    • 1





      @Guy It still seems to time out with that, this text is tricky to get a hold of but I think the other answer has given the best results. Thanks for your help.

      – LRBrady
      Nov 13 '18 at 13:12















    3














    The xpath is wrong. It fails in /div[2], it doesn't match anything. This is an example why you shouldn't use absolute path.



    The section has id attribute, use it



    betweenLugs = driver.find_elements(By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")[0]


    You might also want to add some wait for the loading



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

    betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")))





    share|improve this answer

























    • That's a better idea, I will try and use your suggestion, however when indexing with [0], I get the error "list index is out of range."

      – LRBrady
      Nov 13 '18 at 12:35







    • 1





      @LRBrady It might be timing issue, I updated my answer.

      – Guy
      Nov 13 '18 at 12:38











    • I appreciate the edit, I'm not sure it's a timing issue because even with the edit, selenium is just timing out and not finding anything. I'll continue with your suggestion and try to make some changes.

      – LRBrady
      Nov 13 '18 at 12:44






    • 1





      @LRBrady Try to maximize the window driver.maximize_window(), call it after the driver initialization.

      – Guy
      Nov 13 '18 at 13:02






    • 1





      @Guy It still seems to time out with that, this text is tricky to get a hold of but I think the other answer has given the best results. Thanks for your help.

      – LRBrady
      Nov 13 '18 at 13:12













    3












    3








    3







    The xpath is wrong. It fails in /div[2], it doesn't match anything. This is an example why you shouldn't use absolute path.



    The section has id attribute, use it



    betweenLugs = driver.find_elements(By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")[0]


    You might also want to add some wait for the loading



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

    betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")))





    share|improve this answer















    The xpath is wrong. It fails in /div[2], it doesn't match anything. This is an example why you shouldn't use absolute path.



    The section has id attribute, use it



    betweenLugs = driver.find_elements(By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")[0]


    You might also want to add some wait for the loading



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

    betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, "//*[@id='product-info-data-5bea7fa7406d7']/ul/li[1]")))






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 13 '18 at 12:38

























    answered Nov 13 '18 at 12:29









    GuyGuy

    19.4k72251




    19.4k72251












    • That's a better idea, I will try and use your suggestion, however when indexing with [0], I get the error "list index is out of range."

      – LRBrady
      Nov 13 '18 at 12:35







    • 1





      @LRBrady It might be timing issue, I updated my answer.

      – Guy
      Nov 13 '18 at 12:38











    • I appreciate the edit, I'm not sure it's a timing issue because even with the edit, selenium is just timing out and not finding anything. I'll continue with your suggestion and try to make some changes.

      – LRBrady
      Nov 13 '18 at 12:44






    • 1





      @LRBrady Try to maximize the window driver.maximize_window(), call it after the driver initialization.

      – Guy
      Nov 13 '18 at 13:02






    • 1





      @Guy It still seems to time out with that, this text is tricky to get a hold of but I think the other answer has given the best results. Thanks for your help.

      – LRBrady
      Nov 13 '18 at 13:12

















    • That's a better idea, I will try and use your suggestion, however when indexing with [0], I get the error "list index is out of range."

      – LRBrady
      Nov 13 '18 at 12:35







    • 1





      @LRBrady It might be timing issue, I updated my answer.

      – Guy
      Nov 13 '18 at 12:38











    • I appreciate the edit, I'm not sure it's a timing issue because even with the edit, selenium is just timing out and not finding anything. I'll continue with your suggestion and try to make some changes.

      – LRBrady
      Nov 13 '18 at 12:44






    • 1





      @LRBrady Try to maximize the window driver.maximize_window(), call it after the driver initialization.

      – Guy
      Nov 13 '18 at 13:02






    • 1





      @Guy It still seems to time out with that, this text is tricky to get a hold of but I think the other answer has given the best results. Thanks for your help.

      – LRBrady
      Nov 13 '18 at 13:12
















    That's a better idea, I will try and use your suggestion, however when indexing with [0], I get the error "list index is out of range."

    – LRBrady
    Nov 13 '18 at 12:35






    That's a better idea, I will try and use your suggestion, however when indexing with [0], I get the error "list index is out of range."

    – LRBrady
    Nov 13 '18 at 12:35





    1




    1





    @LRBrady It might be timing issue, I updated my answer.

    – Guy
    Nov 13 '18 at 12:38





    @LRBrady It might be timing issue, I updated my answer.

    – Guy
    Nov 13 '18 at 12:38













    I appreciate the edit, I'm not sure it's a timing issue because even with the edit, selenium is just timing out and not finding anything. I'll continue with your suggestion and try to make some changes.

    – LRBrady
    Nov 13 '18 at 12:44





    I appreciate the edit, I'm not sure it's a timing issue because even with the edit, selenium is just timing out and not finding anything. I'll continue with your suggestion and try to make some changes.

    – LRBrady
    Nov 13 '18 at 12:44




    1




    1





    @LRBrady Try to maximize the window driver.maximize_window(), call it after the driver initialization.

    – Guy
    Nov 13 '18 at 13:02





    @LRBrady Try to maximize the window driver.maximize_window(), call it after the driver initialization.

    – Guy
    Nov 13 '18 at 13:02




    1




    1





    @Guy It still seems to time out with that, this text is tricky to get a hold of but I think the other answer has given the best results. Thanks for your help.

    – LRBrady
    Nov 13 '18 at 13:12





    @Guy It still seems to time out with that, this text is tricky to get a hold of but I think the other answer has given the best results. Thanks for your help.

    – LRBrady
    Nov 13 '18 at 13:12











    2














    That page already has jQuery on it so you can just:



    driver.execute_script("return jQuery('li:contains(Between lugs)').text().trim().replace(/s+/g, ' ')")


    You can fiddle with selectors in the chrome selectors, it makes it much easier.






    share|improve this answer























    • Very interesting. Thanks.

      – QHarr
      Nov 14 '18 at 8:11















    2














    That page already has jQuery on it so you can just:



    driver.execute_script("return jQuery('li:contains(Between lugs)').text().trim().replace(/s+/g, ' ')")


    You can fiddle with selectors in the chrome selectors, it makes it much easier.






    share|improve this answer























    • Very interesting. Thanks.

      – QHarr
      Nov 14 '18 at 8:11













    2












    2








    2







    That page already has jQuery on it so you can just:



    driver.execute_script("return jQuery('li:contains(Between lugs)').text().trim().replace(/s+/g, ' ')")


    You can fiddle with selectors in the chrome selectors, it makes it much easier.






    share|improve this answer













    That page already has jQuery on it so you can just:



    driver.execute_script("return jQuery('li:contains(Between lugs)').text().trim().replace(/s+/g, ' ')")


    You can fiddle with selectors in the chrome selectors, it makes it much easier.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 14 '18 at 0:46









    pguardiariopguardiario

    36.7k980117




    36.7k980117












    • Very interesting. Thanks.

      – QHarr
      Nov 14 '18 at 8:11

















    • Very interesting. Thanks.

      – QHarr
      Nov 14 '18 at 8:11
















    Very interesting. Thanks.

    – QHarr
    Nov 14 '18 at 8:11





    Very interesting. Thanks.

    – QHarr
    Nov 14 '18 at 8:11











    1














    Another simpler approach might be the following one:



    from contextlib import closing
    from selenium import webdriver
    from selenium.webdriver.support import ui

    url = "https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001"

    with closing(webdriver.Chrome()) as wd:
    wait = ui.WebDriverWait(wd, 10)
    wd.get(url)
    item = wait.until(lambda wd: wd.find_element_by_xpath("//*[contains(@class,'technical-data')]//li")).get_attribute('textContent')
    print(' '.join(item.split()))


    Output:



    Between lugs: 20 mm





    share|improve this answer























    • Do I see a context manager? ;-) +

      – QHarr
      Nov 13 '18 at 19:20






    • 1





      I find it very handy when It comes to open and quit the browser in a single shot @QHarr. Thanks.

      – SIM
      Nov 13 '18 at 19:33















    1














    Another simpler approach might be the following one:



    from contextlib import closing
    from selenium import webdriver
    from selenium.webdriver.support import ui

    url = "https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001"

    with closing(webdriver.Chrome()) as wd:
    wait = ui.WebDriverWait(wd, 10)
    wd.get(url)
    item = wait.until(lambda wd: wd.find_element_by_xpath("//*[contains(@class,'technical-data')]//li")).get_attribute('textContent')
    print(' '.join(item.split()))


    Output:



    Between lugs: 20 mm





    share|improve this answer























    • Do I see a context manager? ;-) +

      – QHarr
      Nov 13 '18 at 19:20






    • 1





      I find it very handy when It comes to open and quit the browser in a single shot @QHarr. Thanks.

      – SIM
      Nov 13 '18 at 19:33













    1












    1








    1







    Another simpler approach might be the following one:



    from contextlib import closing
    from selenium import webdriver
    from selenium.webdriver.support import ui

    url = "https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001"

    with closing(webdriver.Chrome()) as wd:
    wait = ui.WebDriverWait(wd, 10)
    wd.get(url)
    item = wait.until(lambda wd: wd.find_element_by_xpath("//*[contains(@class,'technical-data')]//li")).get_attribute('textContent')
    print(' '.join(item.split()))


    Output:



    Between lugs: 20 mm





    share|improve this answer













    Another simpler approach might be the following one:



    from contextlib import closing
    from selenium import webdriver
    from selenium.webdriver.support import ui

    url = "https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001"

    with closing(webdriver.Chrome()) as wd:
    wait = ui.WebDriverWait(wd, 10)
    wd.get(url)
    item = wait.until(lambda wd: wd.find_element_by_xpath("//*[contains(@class,'technical-data')]//li")).get_attribute('textContent')
    print(' '.join(item.split()))


    Output:



    Between lugs: 20 mm






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 17:57









    SIMSIM

    10.7k31046




    10.7k31046












    • Do I see a context manager? ;-) +

      – QHarr
      Nov 13 '18 at 19:20






    • 1





      I find it very handy when It comes to open and quit the browser in a single shot @QHarr. Thanks.

      – SIM
      Nov 13 '18 at 19:33

















    • Do I see a context manager? ;-) +

      – QHarr
      Nov 13 '18 at 19:20






    • 1





      I find it very handy when It comes to open and quit the browser in a single shot @QHarr. Thanks.

      – SIM
      Nov 13 '18 at 19:33
















    Do I see a context manager? ;-) +

    – QHarr
    Nov 13 '18 at 19:20





    Do I see a context manager? ;-) +

    – QHarr
    Nov 13 '18 at 19:20




    1




    1





    I find it very handy when It comes to open and quit the browser in a single shot @QHarr. Thanks.

    – SIM
    Nov 13 '18 at 19:33





    I find it very handy when It comes to open and quit the browser in a single shot @QHarr. Thanks.

    – SIM
    Nov 13 '18 at 19:33











    0














    Using a scroll down and a wait with a css selector to target the parent li



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

    driver = webdriver.Chrome() #Firefox()
    driver.get("https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001")
    driver.execute_script("window.scrollTo(0, 2000)")
    betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, "#product-info-data-5beaf5497d916 > ul > li:nth-child(1)")))

    print(betweenLugs.text)





    share|improve this answer



























      0














      Using a scroll down and a wait with a css selector to target the parent li



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

      driver = webdriver.Chrome() #Firefox()
      driver.get("https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001")
      driver.execute_script("window.scrollTo(0, 2000)")
      betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, "#product-info-data-5beaf5497d916 > ul > li:nth-child(1)")))

      print(betweenLugs.text)





      share|improve this answer

























        0












        0








        0







        Using a scroll down and a wait with a css selector to target the parent li



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

        driver = webdriver.Chrome() #Firefox()
        driver.get("https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001")
        driver.execute_script("window.scrollTo(0, 2000)")
        betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, "#product-info-data-5beaf5497d916 > ul > li:nth-child(1)")))

        print(betweenLugs.text)





        share|improve this answer













        Using a scroll down and a wait with a css selector to target the parent li



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

        driver = webdriver.Chrome() #Firefox()
        driver.get("https://www.omegawatches.com/watch-omega-specialities-first-omega-wrist-chronograph-51652483004001")
        driver.execute_script("window.scrollTo(0, 2000)")
        betweenLugs = WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, "#product-info-data-5beaf5497d916 > ul > li:nth-child(1)")))

        print(betweenLugs.text)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 16:19









        QHarrQHarr

        36.2k82144




        36.2k82144



























            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%2f53280886%2fgrabbing-text-from-a-list-with-no-id-or-class-using-selenium%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







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Crossroads (UK TV series)

            ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế