How to get Text from a div element returns just a “.” with Selenium
up vote
0
down vote
favorite
I have a div element which looks like below.
I identify this element with the following xpath.
//*[contains(@class,'ce-component-title')]
Selenium identifies this element and loads the WebElement object. But when I go to get its text, I'm just getting a "." as shown below instead of getting "Purchase to pay process". What am I doing wrong here? I checked the chrome console and there's no other element matching this xpath.
Any help would be much appreciated.
java selenium xpath css-selectors webdriverwait
add a comment |
up vote
0
down vote
favorite
I have a div element which looks like below.
I identify this element with the following xpath.
//*[contains(@class,'ce-component-title')]
Selenium identifies this element and loads the WebElement object. But when I go to get its text, I'm just getting a "." as shown below instead of getting "Purchase to pay process". What am I doing wrong here? I checked the chrome console and there's no other element matching this xpath.
Any help would be much appreciated.
java selenium xpath css-selectors webdriverwait
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a div element which looks like below.
I identify this element with the following xpath.
//*[contains(@class,'ce-component-title')]
Selenium identifies this element and loads the WebElement object. But when I go to get its text, I'm just getting a "." as shown below instead of getting "Purchase to pay process". What am I doing wrong here? I checked the chrome console and there's no other element matching this xpath.
Any help would be much appreciated.
java selenium xpath css-selectors webdriverwait
I have a div element which looks like below.
I identify this element with the following xpath.
//*[contains(@class,'ce-component-title')]
Selenium identifies this element and loads the WebElement object. But when I go to get its text, I'm just getting a "." as shown below instead of getting "Purchase to pay process". What am I doing wrong here? I checked the chrome console and there's no other element matching this xpath.
Any help would be much appreciated.
java selenium xpath css-selectors webdriverwait
java selenium xpath css-selectors webdriverwait
edited Nov 20 at 5:01
DebanjanB
37.7k73375
37.7k73375
asked Nov 20 at 4:36
mayooran
1,65932856
1,65932856
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");
xpath
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");
Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
– mayooran
Nov 20 at 8:53
Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
– DebanjanB
Nov 20 at 9:02
add a comment |
up vote
0
down vote
I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
Try using console of your browser, to verify how many elements this xpath returns.
I can help you if you give me url to this page.
add a comment |
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
});
}
});
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%2f53386312%2fhow-to-get-text-from-a-div-element-returns-just-a-with-selenium%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
up vote
1
down vote
As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");
xpath
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");
Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
– mayooran
Nov 20 at 8:53
Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
– DebanjanB
Nov 20 at 9:02
add a comment |
up vote
1
down vote
As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");
xpath
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");
Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
– mayooran
Nov 20 at 8:53
Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
– DebanjanB
Nov 20 at 9:02
add a comment |
up vote
1
down vote
up vote
1
down vote
As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");
xpath
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");
As per the HTML you have shared the element is an Angular element so you have to induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
cssSelector
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[ng-if*='getTitle']>div.ce-component-title"))).getAttribute("innerHTML");
xpath
:
String myString = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@ng-if,'getTitle')]/div[@class='ce-component-title flex text-overflow ng-binding']"))).getAttribute("innerHTML");
edited Nov 20 at 9:01
answered Nov 20 at 4:56
DebanjanB
37.7k73375
37.7k73375
Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
– mayooran
Nov 20 at 8:53
Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
– DebanjanB
Nov 20 at 9:02
add a comment |
Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
– mayooran
Nov 20 at 8:53
Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
– DebanjanB
Nov 20 at 9:02
Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
– mayooran
Nov 20 at 8:53
Thanks for the answer Deb. If the element is not visible, I would get an element not found exception right? I have the element in my WebElement object. Just that the get text method returns a ".".
– mayooran
Nov 20 at 8:53
Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
– DebanjanB
Nov 20 at 9:02
Nopes, if the element is not visible you would get ElementNotVisible exception. How about the solution? Did it work?
– DebanjanB
Nov 20 at 9:02
add a comment |
up vote
0
down vote
I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
Try using console of your browser, to verify how many elements this xpath returns.
I can help you if you give me url to this page.
add a comment |
up vote
0
down vote
I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
Try using console of your browser, to verify how many elements this xpath returns.
I can help you if you give me url to this page.
add a comment |
up vote
0
down vote
up vote
0
down vote
I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
Try using console of your browser, to verify how many elements this xpath returns.
I can help you if you give me url to this page.
I think your xpath (//*[contains(@class,'ce-component-title')]) returns more than one element, and the element you need is not the first one.
Try using console of your browser, to verify how many elements this xpath returns.
I can help you if you give me url to this page.
edited Nov 23 at 15:31
meagar♦
176k29272288
176k29272288
answered Nov 21 at 1:28
Dmitry
35427
35427
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%2f53386312%2fhow-to-get-text-from-a-div-element-returns-just-a-with-selenium%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