My question about xpath not working on Selenium

Multi tool use
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();
java selenium selenium-webdriver xpath selenium-chromedriver
|
show 4 more comments
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();
java selenium selenium-webdriver xpath selenium-chromedriver
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
|
show 4 more comments
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();
java selenium selenium-webdriver xpath selenium-chromedriver
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
java selenium selenium-webdriver xpath selenium-chromedriver
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
|
show 4 more comments
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
|
show 4 more comments
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));
add a comment |
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));
add a comment |
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));
add a comment |
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));
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));
answered Nov 5 at 20:48
Carl
406
406
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
mdKJPv8R7v4R3m9N v,7J2h9f,TQpCcGxDLpxJ32A5J EixZzVVNc3y B8pbGW14SkZbKvflyclITgdlzqhbMiyef3
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