Selenium: finding the right element identifier
up vote
1
down vote
favorite
I'm relatively new to selenium automation, and am trying to test a form that has been created for me. I'd like to put test values into a textbox whose HTML code looks like:
<input type="text" id="txtEndCustId" onkeypress="return isNumberKey(event);" class="Text" required="" onfocus="txtEndCustIdFocus('Your customer END CUSTOMER DEP ID');" onblur="txtEndCustIdblur();">
I thought I'd use the "id" of the box, but the code:
Dim options As New Chrome.ChromeOptions
Dim service As ChromeDriverService = ChromeDriverService.CreateDefaultService
Dim wd As New Chrome.ChromeDriver(service, options)
wd.Navigate.GoToUrl("x")
wd.FindElementById("txtEndCustId").SendKeys("1")
Gives an error:
Unable to locate element: {"method":"id","selector":"txtEndCustId"}
To be perfectly honest I've no idea where I went wrong here - thanks in advance for your help.
Is there any "List All Element ids" function, so that I can marry them up with what's shown in the chrome inspector view?
vb.net selenium selenium-chromedriver
|
show 1 more comment
up vote
1
down vote
favorite
I'm relatively new to selenium automation, and am trying to test a form that has been created for me. I'd like to put test values into a textbox whose HTML code looks like:
<input type="text" id="txtEndCustId" onkeypress="return isNumberKey(event);" class="Text" required="" onfocus="txtEndCustIdFocus('Your customer END CUSTOMER DEP ID');" onblur="txtEndCustIdblur();">
I thought I'd use the "id" of the box, but the code:
Dim options As New Chrome.ChromeOptions
Dim service As ChromeDriverService = ChromeDriverService.CreateDefaultService
Dim wd As New Chrome.ChromeDriver(service, options)
wd.Navigate.GoToUrl("x")
wd.FindElementById("txtEndCustId").SendKeys("1")
Gives an error:
Unable to locate element: {"method":"id","selector":"txtEndCustId"}
To be perfectly honest I've no idea where I went wrong here - thanks in advance for your help.
Is there any "List All Element ids" function, so that I can marry them up with what's shown in the chrome inspector view?
vb.net selenium selenium-chromedriver
Please provide the entire line of code where you are trying to get the element by it's ID, (...) does not give enough information.
– Ryan Wilson
Nov 21 at 15:52
Sorry, it's just the chromedriver object - I've expanded the sample code now
– Martin KS
Nov 21 at 16:01
IS it possible you are trying to get the element before the page has fully loaded?? You may want to read this SO post on how to do a wait with webdriver (stackoverflow.com/questions/13244225/…)
– Ryan Wilson
Nov 21 at 16:07
no, I'm stepping through the code in the debugger, and it doesn't even allow me to step to that line before the page has finished the 'navigate' line and fully loaded - or at least it appears visually to be fully loaded, and the chromium window can see the element if I hit F12 there.
– Martin KS
Nov 21 at 16:14
@MartingKS is the element you want wrapped inside a frame, iframe?
– Ryan Wilson
Nov 21 at 16:18
|
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm relatively new to selenium automation, and am trying to test a form that has been created for me. I'd like to put test values into a textbox whose HTML code looks like:
<input type="text" id="txtEndCustId" onkeypress="return isNumberKey(event);" class="Text" required="" onfocus="txtEndCustIdFocus('Your customer END CUSTOMER DEP ID');" onblur="txtEndCustIdblur();">
I thought I'd use the "id" of the box, but the code:
Dim options As New Chrome.ChromeOptions
Dim service As ChromeDriverService = ChromeDriverService.CreateDefaultService
Dim wd As New Chrome.ChromeDriver(service, options)
wd.Navigate.GoToUrl("x")
wd.FindElementById("txtEndCustId").SendKeys("1")
Gives an error:
Unable to locate element: {"method":"id","selector":"txtEndCustId"}
To be perfectly honest I've no idea where I went wrong here - thanks in advance for your help.
Is there any "List All Element ids" function, so that I can marry them up with what's shown in the chrome inspector view?
vb.net selenium selenium-chromedriver
I'm relatively new to selenium automation, and am trying to test a form that has been created for me. I'd like to put test values into a textbox whose HTML code looks like:
<input type="text" id="txtEndCustId" onkeypress="return isNumberKey(event);" class="Text" required="" onfocus="txtEndCustIdFocus('Your customer END CUSTOMER DEP ID');" onblur="txtEndCustIdblur();">
I thought I'd use the "id" of the box, but the code:
Dim options As New Chrome.ChromeOptions
Dim service As ChromeDriverService = ChromeDriverService.CreateDefaultService
Dim wd As New Chrome.ChromeDriver(service, options)
wd.Navigate.GoToUrl("x")
wd.FindElementById("txtEndCustId").SendKeys("1")
Gives an error:
Unable to locate element: {"method":"id","selector":"txtEndCustId"}
To be perfectly honest I've no idea where I went wrong here - thanks in advance for your help.
Is there any "List All Element ids" function, so that I can marry them up with what's shown in the chrome inspector view?
vb.net selenium selenium-chromedriver
vb.net selenium selenium-chromedriver
edited Nov 21 at 16:00
asked Nov 21 at 15:51
Martin KS
141218
141218
Please provide the entire line of code where you are trying to get the element by it's ID, (...) does not give enough information.
– Ryan Wilson
Nov 21 at 15:52
Sorry, it's just the chromedriver object - I've expanded the sample code now
– Martin KS
Nov 21 at 16:01
IS it possible you are trying to get the element before the page has fully loaded?? You may want to read this SO post on how to do a wait with webdriver (stackoverflow.com/questions/13244225/…)
– Ryan Wilson
Nov 21 at 16:07
no, I'm stepping through the code in the debugger, and it doesn't even allow me to step to that line before the page has finished the 'navigate' line and fully loaded - or at least it appears visually to be fully loaded, and the chromium window can see the element if I hit F12 there.
– Martin KS
Nov 21 at 16:14
@MartingKS is the element you want wrapped inside a frame, iframe?
– Ryan Wilson
Nov 21 at 16:18
|
show 1 more comment
Please provide the entire line of code where you are trying to get the element by it's ID, (...) does not give enough information.
– Ryan Wilson
Nov 21 at 15:52
Sorry, it's just the chromedriver object - I've expanded the sample code now
– Martin KS
Nov 21 at 16:01
IS it possible you are trying to get the element before the page has fully loaded?? You may want to read this SO post on how to do a wait with webdriver (stackoverflow.com/questions/13244225/…)
– Ryan Wilson
Nov 21 at 16:07
no, I'm stepping through the code in the debugger, and it doesn't even allow me to step to that line before the page has finished the 'navigate' line and fully loaded - or at least it appears visually to be fully loaded, and the chromium window can see the element if I hit F12 there.
– Martin KS
Nov 21 at 16:14
@MartingKS is the element you want wrapped inside a frame, iframe?
– Ryan Wilson
Nov 21 at 16:18
Please provide the entire line of code where you are trying to get the element by it's ID, (...) does not give enough information.
– Ryan Wilson
Nov 21 at 15:52
Please provide the entire line of code where you are trying to get the element by it's ID, (...) does not give enough information.
– Ryan Wilson
Nov 21 at 15:52
Sorry, it's just the chromedriver object - I've expanded the sample code now
– Martin KS
Nov 21 at 16:01
Sorry, it's just the chromedriver object - I've expanded the sample code now
– Martin KS
Nov 21 at 16:01
IS it possible you are trying to get the element before the page has fully loaded?? You may want to read this SO post on how to do a wait with webdriver (stackoverflow.com/questions/13244225/…)
– Ryan Wilson
Nov 21 at 16:07
IS it possible you are trying to get the element before the page has fully loaded?? You may want to read this SO post on how to do a wait with webdriver (stackoverflow.com/questions/13244225/…)
– Ryan Wilson
Nov 21 at 16:07
no, I'm stepping through the code in the debugger, and it doesn't even allow me to step to that line before the page has finished the 'navigate' line and fully loaded - or at least it appears visually to be fully loaded, and the chromium window can see the element if I hit F12 there.
– Martin KS
Nov 21 at 16:14
no, I'm stepping through the code in the debugger, and it doesn't even allow me to step to that line before the page has finished the 'navigate' line and fully loaded - or at least it appears visually to be fully loaded, and the chromium window can see the element if I hit F12 there.
– Martin KS
Nov 21 at 16:14
@MartingKS is the element you want wrapped inside a frame, iframe?
– Ryan Wilson
Nov 21 at 16:18
@MartingKS is the element you want wrapped inside a frame, iframe?
– Ryan Wilson
Nov 21 at 16:18
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Since your element is inside a frame, you need to navigate the driver to the frame first, a frame has it's own Document containing x number of DOM elements.
First switch to the frame:
//You need to use method switchTo() to set the driver to the frame document
//In this case we are passing in the id of the iframe
wd.switchTo().frame("ctl00_CPH_iframeCat");
//Now that the driver is working on the frame document, you should be able to manipulate the
//input you want
wd.FindElementById("txtEndCustId").SendKeys("1")
//Finally, switch the driver back to the main page document (original document which contains the frames)
driver.switchTo().defaultContent();
Here is a good piece of documentation which should explain this in more detail:
(http://www.assertselenium.com/webdriver/handling-iframes-using-webdriver/)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Since your element is inside a frame, you need to navigate the driver to the frame first, a frame has it's own Document containing x number of DOM elements.
First switch to the frame:
//You need to use method switchTo() to set the driver to the frame document
//In this case we are passing in the id of the iframe
wd.switchTo().frame("ctl00_CPH_iframeCat");
//Now that the driver is working on the frame document, you should be able to manipulate the
//input you want
wd.FindElementById("txtEndCustId").SendKeys("1")
//Finally, switch the driver back to the main page document (original document which contains the frames)
driver.switchTo().defaultContent();
Here is a good piece of documentation which should explain this in more detail:
(http://www.assertselenium.com/webdriver/handling-iframes-using-webdriver/)
add a comment |
up vote
1
down vote
accepted
Since your element is inside a frame, you need to navigate the driver to the frame first, a frame has it's own Document containing x number of DOM elements.
First switch to the frame:
//You need to use method switchTo() to set the driver to the frame document
//In this case we are passing in the id of the iframe
wd.switchTo().frame("ctl00_CPH_iframeCat");
//Now that the driver is working on the frame document, you should be able to manipulate the
//input you want
wd.FindElementById("txtEndCustId").SendKeys("1")
//Finally, switch the driver back to the main page document (original document which contains the frames)
driver.switchTo().defaultContent();
Here is a good piece of documentation which should explain this in more detail:
(http://www.assertselenium.com/webdriver/handling-iframes-using-webdriver/)
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Since your element is inside a frame, you need to navigate the driver to the frame first, a frame has it's own Document containing x number of DOM elements.
First switch to the frame:
//You need to use method switchTo() to set the driver to the frame document
//In this case we are passing in the id of the iframe
wd.switchTo().frame("ctl00_CPH_iframeCat");
//Now that the driver is working on the frame document, you should be able to manipulate the
//input you want
wd.FindElementById("txtEndCustId").SendKeys("1")
//Finally, switch the driver back to the main page document (original document which contains the frames)
driver.switchTo().defaultContent();
Here is a good piece of documentation which should explain this in more detail:
(http://www.assertselenium.com/webdriver/handling-iframes-using-webdriver/)
Since your element is inside a frame, you need to navigate the driver to the frame first, a frame has it's own Document containing x number of DOM elements.
First switch to the frame:
//You need to use method switchTo() to set the driver to the frame document
//In this case we are passing in the id of the iframe
wd.switchTo().frame("ctl00_CPH_iframeCat");
//Now that the driver is working on the frame document, you should be able to manipulate the
//input you want
wd.FindElementById("txtEndCustId").SendKeys("1")
//Finally, switch the driver back to the main page document (original document which contains the frames)
driver.switchTo().defaultContent();
Here is a good piece of documentation which should explain this in more detail:
(http://www.assertselenium.com/webdriver/handling-iframes-using-webdriver/)
answered Nov 21 at 16:52
Ryan Wilson
3,3701418
3,3701418
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415788%2fselenium-finding-the-right-element-identifier%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
Please provide the entire line of code where you are trying to get the element by it's ID, (...) does not give enough information.
– Ryan Wilson
Nov 21 at 15:52
Sorry, it's just the chromedriver object - I've expanded the sample code now
– Martin KS
Nov 21 at 16:01
IS it possible you are trying to get the element before the page has fully loaded?? You may want to read this SO post on how to do a wait with webdriver (stackoverflow.com/questions/13244225/…)
– Ryan Wilson
Nov 21 at 16:07
no, I'm stepping through the code in the debugger, and it doesn't even allow me to step to that line before the page has finished the 'navigate' line and fully loaded - or at least it appears visually to be fully loaded, and the chromium window can see the element if I hit F12 there.
– Martin KS
Nov 21 at 16:14
@MartingKS is the element you want wrapped inside a frame, iframe?
– Ryan Wilson
Nov 21 at 16:18