My question about xpath not working on Selenium











up vote
0
down vote

favorite












I'm trying to download files for a specific date from a website using Selenium's xpath like below. I'm using it to find the link I want from a website form.



driver.findElement(By.xpath("//tr[td[contains(.,'10/30/2018')] and @class='Row ']//span")).click();


When I directly search the HTML in Chrome browser using xpath, it gaves me the result I want. However, if I use Selenium' xpath (web driver is Chrome's) in java program to locate the element, I got "No Such Element Exception". I have tried longer wait for web loading using



driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


But it did not work.



Could anyone tell me why?



I see that the link is located in a "iframe" tag. Is it something I should deal with first?



The web structure is basically like this



<tr>
<tr class="Row ">
<td>10/30/2018 9:00:00 PM<td>
<td>
<span>
<input type="submit" value="Download"></input>
<input type="hidden"></input>
</span>
</td>
</tr>
<tr class="Row ">
<td>10/27/2018 9:00:00 PM<td>
<td>
<span>
<input type="submit" value="Download"></input>
<input type="hidden"></input>
</span>
</td>
</tr>
</tr>


I also tried this and did not work.



driver.findElement(By.xpath("//tr[td[contains(.,'10/30/2018')] and @class='Row ']//input[@type='submit']")).click();









share|improve this question
























  • Can you show the html structure that is underlying to this question? Maybe the xpath is wrong...
    – michaeak
    Nov 5 at 17:05










  • I have added the structure. I thought my xpath would be right because it worked when I directly use it for search in the website
    – Carl
    Nov 5 at 17:36










  • try this: //tr/td[contains(text(),'10/30/2018') and contains(@class,'Row')]/../td/span
    – Kiril S.
    Nov 5 at 17:37










  • Like on a website when you "Inspect Element" and "Ctrl + F" and input the xpath, and the desired element is located. It just did not work using Selenium in my java program.
    – Carl
    Nov 5 at 17:37










  • The implicitWait() only waits the DOM to be loaded, but the //tr element you're looking for seems to be dynamically loaded. Did you try explicitly wait to the element using a WebDriverWait() ?
    – Renato
    Nov 5 at 17:38















up vote
0
down vote

favorite












I'm trying to download files for a specific date from a website using Selenium's xpath like below. I'm using it to find the link I want from a website form.



driver.findElement(By.xpath("//tr[td[contains(.,'10/30/2018')] and @class='Row ']//span")).click();


When I directly search the HTML in Chrome browser using xpath, it gaves me the result I want. However, if I use Selenium' xpath (web driver is Chrome's) in java program to locate the element, I got "No Such Element Exception". I have tried longer wait for web loading using



driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


But it did not work.



Could anyone tell me why?



I see that the link is located in a "iframe" tag. Is it something I should deal with first?



The web structure is basically like this



<tr>
<tr class="Row ">
<td>10/30/2018 9:00:00 PM<td>
<td>
<span>
<input type="submit" value="Download"></input>
<input type="hidden"></input>
</span>
</td>
</tr>
<tr class="Row ">
<td>10/27/2018 9:00:00 PM<td>
<td>
<span>
<input type="submit" value="Download"></input>
<input type="hidden"></input>
</span>
</td>
</tr>
</tr>


I also tried this and did not work.



driver.findElement(By.xpath("//tr[td[contains(.,'10/30/2018')] and @class='Row ']//input[@type='submit']")).click();









share|improve this question
























  • Can you show the html structure that is underlying to this question? Maybe the xpath is wrong...
    – michaeak
    Nov 5 at 17:05










  • I have added the structure. I thought my xpath would be right because it worked when I directly use it for search in the website
    – Carl
    Nov 5 at 17:36










  • try this: //tr/td[contains(text(),'10/30/2018') and contains(@class,'Row')]/../td/span
    – Kiril S.
    Nov 5 at 17:37










  • Like on a website when you "Inspect Element" and "Ctrl + F" and input the xpath, and the desired element is located. It just did not work using Selenium in my java program.
    – Carl
    Nov 5 at 17:37










  • The implicitWait() only waits the DOM to be loaded, but the //tr element you're looking for seems to be dynamically loaded. Did you try explicitly wait to the element using a WebDriverWait() ?
    – Renato
    Nov 5 at 17:38













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to download files for a specific date from a website using Selenium's xpath like below. I'm using it to find the link I want from a website form.



driver.findElement(By.xpath("//tr[td[contains(.,'10/30/2018')] and @class='Row ']//span")).click();


When I directly search the HTML in Chrome browser using xpath, it gaves me the result I want. However, if I use Selenium' xpath (web driver is Chrome's) in java program to locate the element, I got "No Such Element Exception". I have tried longer wait for web loading using



driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


But it did not work.



Could anyone tell me why?



I see that the link is located in a "iframe" tag. Is it something I should deal with first?



The web structure is basically like this



<tr>
<tr class="Row ">
<td>10/30/2018 9:00:00 PM<td>
<td>
<span>
<input type="submit" value="Download"></input>
<input type="hidden"></input>
</span>
</td>
</tr>
<tr class="Row ">
<td>10/27/2018 9:00:00 PM<td>
<td>
<span>
<input type="submit" value="Download"></input>
<input type="hidden"></input>
</span>
</td>
</tr>
</tr>


I also tried this and did not work.



driver.findElement(By.xpath("//tr[td[contains(.,'10/30/2018')] and @class='Row ']//input[@type='submit']")).click();









share|improve this question















I'm trying to download files for a specific date from a website using Selenium's xpath like below. I'm using it to find the link I want from a website form.



driver.findElement(By.xpath("//tr[td[contains(.,'10/30/2018')] and @class='Row ']//span")).click();


When I directly search the HTML in Chrome browser using xpath, it gaves me the result I want. However, if I use Selenium' xpath (web driver is Chrome's) in java program to locate the element, I got "No Such Element Exception". I have tried longer wait for web loading using



driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


But it did not work.



Could anyone tell me why?



I see that the link is located in a "iframe" tag. Is it something I should deal with first?



The web structure is basically like this



<tr>
<tr class="Row ">
<td>10/30/2018 9:00:00 PM<td>
<td>
<span>
<input type="submit" value="Download"></input>
<input type="hidden"></input>
</span>
</td>
</tr>
<tr class="Row ">
<td>10/27/2018 9:00:00 PM<td>
<td>
<span>
<input type="submit" value="Download"></input>
<input type="hidden"></input>
</span>
</td>
</tr>
</tr>


I also tried this and did not work.



driver.findElement(By.xpath("//tr[td[contains(.,'10/30/2018')] and @class='Row ']//input[@type='submit']")).click();






java selenium selenium-webdriver xpath selenium-chromedriver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 5 at 20:00

























asked Nov 5 at 16:59









Carl

406




406












  • Can you show the html structure that is underlying to this question? Maybe the xpath is wrong...
    – michaeak
    Nov 5 at 17:05










  • I have added the structure. I thought my xpath would be right because it worked when I directly use it for search in the website
    – Carl
    Nov 5 at 17:36










  • try this: //tr/td[contains(text(),'10/30/2018') and contains(@class,'Row')]/../td/span
    – Kiril S.
    Nov 5 at 17:37










  • Like on a website when you "Inspect Element" and "Ctrl + F" and input the xpath, and the desired element is located. It just did not work using Selenium in my java program.
    – Carl
    Nov 5 at 17:37










  • The implicitWait() only waits the DOM to be loaded, but the //tr element you're looking for seems to be dynamically loaded. Did you try explicitly wait to the element using a WebDriverWait() ?
    – Renato
    Nov 5 at 17:38


















  • Can you show the html structure that is underlying to this question? Maybe the xpath is wrong...
    – michaeak
    Nov 5 at 17:05










  • I have added the structure. I thought my xpath would be right because it worked when I directly use it for search in the website
    – Carl
    Nov 5 at 17:36










  • try this: //tr/td[contains(text(),'10/30/2018') and contains(@class,'Row')]/../td/span
    – Kiril S.
    Nov 5 at 17:37










  • Like on a website when you "Inspect Element" and "Ctrl + F" and input the xpath, and the desired element is located. It just did not work using Selenium in my java program.
    – Carl
    Nov 5 at 17:37










  • The implicitWait() only waits the DOM to be loaded, but the //tr element you're looking for seems to be dynamically loaded. Did you try explicitly wait to the element using a WebDriverWait() ?
    – Renato
    Nov 5 at 17:38
















Can you show the html structure that is underlying to this question? Maybe the xpath is wrong...
– michaeak
Nov 5 at 17:05




Can you show the html structure that is underlying to this question? Maybe the xpath is wrong...
– michaeak
Nov 5 at 17:05












I have added the structure. I thought my xpath would be right because it worked when I directly use it for search in the website
– Carl
Nov 5 at 17:36




I have added the structure. I thought my xpath would be right because it worked when I directly use it for search in the website
– Carl
Nov 5 at 17:36












try this: //tr/td[contains(text(),'10/30/2018') and contains(@class,'Row')]/../td/span
– Kiril S.
Nov 5 at 17:37




try this: //tr/td[contains(text(),'10/30/2018') and contains(@class,'Row')]/../td/span
– Kiril S.
Nov 5 at 17:37












Like on a website when you "Inspect Element" and "Ctrl + F" and input the xpath, and the desired element is located. It just did not work using Selenium in my java program.
– Carl
Nov 5 at 17:37




Like on a website when you "Inspect Element" and "Ctrl + F" and input the xpath, and the desired element is located. It just did not work using Selenium in my java program.
– Carl
Nov 5 at 17:37












The implicitWait() only waits the DOM to be loaded, but the //tr element you're looking for seems to be dynamically loaded. Did you try explicitly wait to the element using a WebDriverWait() ?
– Renato
Nov 5 at 17:38




The implicitWait() only waits the DOM to be loaded, but the //tr element you're looking for seems to be dynamically loaded. Did you try explicitly wait to the element using a WebDriverWait() ?
– Renato
Nov 5 at 17:38












1 Answer
1






active

oldest

votes

















up vote
0
down vote













My question is solved. The reason I cannot find the element is that it's in a iframe tag. It mean it's another website inside the current website. To handle that, I need to use switchTo function to go to that website first, then I can work on it.



driver.switchTo().frame(driver.findElements(By.tagName("iframe")).get(0)); 





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',
    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%2f53158895%2fmy-question-about-xpath-not-working-on-selenium%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    My question is solved. The reason I cannot find the element is that it's in a iframe tag. It mean it's another website inside the current website. To handle that, I need to use switchTo function to go to that website first, then I can work on it.



    driver.switchTo().frame(driver.findElements(By.tagName("iframe")).get(0)); 





    share|improve this answer

























      up vote
      0
      down vote













      My question is solved. The reason I cannot find the element is that it's in a iframe tag. It mean it's another website inside the current website. To handle that, I need to use switchTo function to go to that website first, then I can work on it.



      driver.switchTo().frame(driver.findElements(By.tagName("iframe")).get(0)); 





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        My question is solved. The reason I cannot find the element is that it's in a iframe tag. It mean it's another website inside the current website. To handle that, I need to use switchTo function to go to that website first, then I can work on it.



        driver.switchTo().frame(driver.findElements(By.tagName("iframe")).get(0)); 





        share|improve this answer












        My question is solved. The reason I cannot find the element is that it's in a iframe tag. It mean it's another website inside the current website. To handle that, I need to use switchTo function to go to that website first, then I can work on it.



        driver.switchTo().frame(driver.findElements(By.tagName("iframe")).get(0)); 






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 5 at 20:48









        Carl

        406




        406






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53158895%2fmy-question-about-xpath-not-working-on-selenium%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini