Python selenium xpath geting text is empty
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
So I have this link and I'm trying to obtain the text from this XPath //div[@class='titlu']
but for some reason sometimes I'm getting the text how it should be and other times I'm receiving an empty string even though the site is containing that text.
What have I tried:
wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Ap. de lux 3 ")))
e = self.driver.find_element_by_xpath(html_data.xpath)
also:
wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, xpath)))
e = self.driver.find_element_by_xpath(xpath)
and also I've used and this type of wait:
self.driver.implicitly_wait(10)
How I'm getting the text at this moment:
self.driver.find_element_by_xpath(xpath).text
the problem that I've faced here is that the text is refusing to appear on some occasions and in others it does, even though the actually XPath is found and it exists already. Maybe is not loaded completely, can any of you give me some advice about how can I fix this?
UPDATE:
Also, I'm trying to get the location and size of that using selenium but both of them are going to be 0. Any idea how can I fix that?
with, height = self.driver.find_element_by_xpath(html_data.xpath).size
x, y = self.driver.find_element_by_xpath(html_data.xpath).location
python html selenium selenium-webdriver xpath
add a comment |
So I have this link and I'm trying to obtain the text from this XPath //div[@class='titlu']
but for some reason sometimes I'm getting the text how it should be and other times I'm receiving an empty string even though the site is containing that text.
What have I tried:
wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Ap. de lux 3 ")))
e = self.driver.find_element_by_xpath(html_data.xpath)
also:
wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, xpath)))
e = self.driver.find_element_by_xpath(xpath)
and also I've used and this type of wait:
self.driver.implicitly_wait(10)
How I'm getting the text at this moment:
self.driver.find_element_by_xpath(xpath).text
the problem that I've faced here is that the text is refusing to appear on some occasions and in others it does, even though the actually XPath is found and it exists already. Maybe is not loaded completely, can any of you give me some advice about how can I fix this?
UPDATE:
Also, I'm trying to get the location and size of that using selenium but both of them are going to be 0. Any idea how can I fix that?
with, height = self.driver.find_element_by_xpath(html_data.xpath).size
x, y = self.driver.find_element_by_xpath(html_data.xpath).location
python html selenium selenium-webdriver xpath
add a comment |
So I have this link and I'm trying to obtain the text from this XPath //div[@class='titlu']
but for some reason sometimes I'm getting the text how it should be and other times I'm receiving an empty string even though the site is containing that text.
What have I tried:
wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Ap. de lux 3 ")))
e = self.driver.find_element_by_xpath(html_data.xpath)
also:
wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, xpath)))
e = self.driver.find_element_by_xpath(xpath)
and also I've used and this type of wait:
self.driver.implicitly_wait(10)
How I'm getting the text at this moment:
self.driver.find_element_by_xpath(xpath).text
the problem that I've faced here is that the text is refusing to appear on some occasions and in others it does, even though the actually XPath is found and it exists already. Maybe is not loaded completely, can any of you give me some advice about how can I fix this?
UPDATE:
Also, I'm trying to get the location and size of that using selenium but both of them are going to be 0. Any idea how can I fix that?
with, height = self.driver.find_element_by_xpath(html_data.xpath).size
x, y = self.driver.find_element_by_xpath(html_data.xpath).location
python html selenium selenium-webdriver xpath
So I have this link and I'm trying to obtain the text from this XPath //div[@class='titlu']
but for some reason sometimes I'm getting the text how it should be and other times I'm receiving an empty string even though the site is containing that text.
What have I tried:
wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Ap. de lux 3 ")))
e = self.driver.find_element_by_xpath(html_data.xpath)
also:
wait = WebDriverWait(self.driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, xpath)))
e = self.driver.find_element_by_xpath(xpath)
and also I've used and this type of wait:
self.driver.implicitly_wait(10)
How I'm getting the text at this moment:
self.driver.find_element_by_xpath(xpath).text
the problem that I've faced here is that the text is refusing to appear on some occasions and in others it does, even though the actually XPath is found and it exists already. Maybe is not loaded completely, can any of you give me some advice about how can I fix this?
UPDATE:
Also, I'm trying to get the location and size of that using selenium but both of them are going to be 0. Any idea how can I fix that?
with, height = self.driver.find_element_by_xpath(html_data.xpath).size
x, y = self.driver.find_element_by_xpath(html_data.xpath).location
python html selenium selenium-webdriver xpath
python html selenium selenium-webdriver xpath
edited Nov 25 '18 at 2:07
Vali
asked Nov 25 '18 at 1:42
ValiVali
1318
1318
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
the first element of //div[@class='titlu']
is hidden and you will not get value if using .text
because it will only extract visible text, use .get_attribute('textContent')
or select second element.
Well thanks it's working but I do have one more question, do you know how can I get also the position of that xpath using selenium? I mean if I'm just getting it likeself.driver.find_element_by_xpath(html_data.xpath).location['x']
is not going to work, I mean the X value or Y will be 0 in both of this cases
– Vali
Nov 25 '18 at 2:05
you can't get position of hidden element. it better to create new post if you have another problem.
– ewwink
Nov 25 '18 at 2:28
add a comment |
You can execute script to access. I learnt this method from an answer by @pguardiario
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = d.execute_script("return [...document.querySelectorAll('div.titlu')].map(item => item.innerText)")
print(items)
d.quit()
add a comment |
@QHarr answer returns required output (+1), but as alternative to that the same output can be achieved with common approach without using JavaScript executor:
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = [item.get_attribute('innerText') for item in d.find_elements_by_xpath("//div[@class='titlu']")]
print(items)
d.quit()
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%2f53463974%2fpython-selenium-xpath-geting-text-is-empty%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
the first element of //div[@class='titlu']
is hidden and you will not get value if using .text
because it will only extract visible text, use .get_attribute('textContent')
or select second element.
Well thanks it's working but I do have one more question, do you know how can I get also the position of that xpath using selenium? I mean if I'm just getting it likeself.driver.find_element_by_xpath(html_data.xpath).location['x']
is not going to work, I mean the X value or Y will be 0 in both of this cases
– Vali
Nov 25 '18 at 2:05
you can't get position of hidden element. it better to create new post if you have another problem.
– ewwink
Nov 25 '18 at 2:28
add a comment |
the first element of //div[@class='titlu']
is hidden and you will not get value if using .text
because it will only extract visible text, use .get_attribute('textContent')
or select second element.
Well thanks it's working but I do have one more question, do you know how can I get also the position of that xpath using selenium? I mean if I'm just getting it likeself.driver.find_element_by_xpath(html_data.xpath).location['x']
is not going to work, I mean the X value or Y will be 0 in both of this cases
– Vali
Nov 25 '18 at 2:05
you can't get position of hidden element. it better to create new post if you have another problem.
– ewwink
Nov 25 '18 at 2:28
add a comment |
the first element of //div[@class='titlu']
is hidden and you will not get value if using .text
because it will only extract visible text, use .get_attribute('textContent')
or select second element.
the first element of //div[@class='titlu']
is hidden and you will not get value if using .text
because it will only extract visible text, use .get_attribute('textContent')
or select second element.
answered Nov 25 '18 at 1:59
ewwinkewwink
12.3k22441
12.3k22441
Well thanks it's working but I do have one more question, do you know how can I get also the position of that xpath using selenium? I mean if I'm just getting it likeself.driver.find_element_by_xpath(html_data.xpath).location['x']
is not going to work, I mean the X value or Y will be 0 in both of this cases
– Vali
Nov 25 '18 at 2:05
you can't get position of hidden element. it better to create new post if you have another problem.
– ewwink
Nov 25 '18 at 2:28
add a comment |
Well thanks it's working but I do have one more question, do you know how can I get also the position of that xpath using selenium? I mean if I'm just getting it likeself.driver.find_element_by_xpath(html_data.xpath).location['x']
is not going to work, I mean the X value or Y will be 0 in both of this cases
– Vali
Nov 25 '18 at 2:05
you can't get position of hidden element. it better to create new post if you have another problem.
– ewwink
Nov 25 '18 at 2:28
Well thanks it's working but I do have one more question, do you know how can I get also the position of that xpath using selenium? I mean if I'm just getting it like
self.driver.find_element_by_xpath(html_data.xpath).location['x']
is not going to work, I mean the X value or Y will be 0 in both of this cases– Vali
Nov 25 '18 at 2:05
Well thanks it's working but I do have one more question, do you know how can I get also the position of that xpath using selenium? I mean if I'm just getting it like
self.driver.find_element_by_xpath(html_data.xpath).location['x']
is not going to work, I mean the X value or Y will be 0 in both of this cases– Vali
Nov 25 '18 at 2:05
you can't get position of hidden element. it better to create new post if you have another problem.
– ewwink
Nov 25 '18 at 2:28
you can't get position of hidden element. it better to create new post if you have another problem.
– ewwink
Nov 25 '18 at 2:28
add a comment |
You can execute script to access. I learnt this method from an answer by @pguardiario
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = d.execute_script("return [...document.querySelectorAll('div.titlu')].map(item => item.innerText)")
print(items)
d.quit()
add a comment |
You can execute script to access. I learnt this method from an answer by @pguardiario
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = d.execute_script("return [...document.querySelectorAll('div.titlu')].map(item => item.innerText)")
print(items)
d.quit()
add a comment |
You can execute script to access. I learnt this method from an answer by @pguardiario
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = d.execute_script("return [...document.querySelectorAll('div.titlu')].map(item => item.innerText)")
print(items)
d.quit()
You can execute script to access. I learnt this method from an answer by @pguardiario
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = d.execute_script("return [...document.querySelectorAll('div.titlu')].map(item => item.innerText)")
print(items)
d.quit()
edited Nov 25 '18 at 4:19
answered Nov 25 '18 at 4:06
QHarrQHarr
39.2k82345
39.2k82345
add a comment |
add a comment |
@QHarr answer returns required output (+1), but as alternative to that the same output can be achieved with common approach without using JavaScript executor:
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = [item.get_attribute('innerText') for item in d.find_elements_by_xpath("//div[@class='titlu']")]
print(items)
d.quit()
add a comment |
@QHarr answer returns required output (+1), but as alternative to that the same output can be achieved with common approach without using JavaScript executor:
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = [item.get_attribute('innerText') for item in d.find_elements_by_xpath("//div[@class='titlu']")]
print(items)
d.quit()
add a comment |
@QHarr answer returns required output (+1), but as alternative to that the same output can be achieved with common approach without using JavaScript executor:
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = [item.get_attribute('innerText') for item in d.find_elements_by_xpath("//div[@class='titlu']")]
print(items)
d.quit()
@QHarr answer returns required output (+1), but as alternative to that the same output can be achieved with common approach without using JavaScript executor:
from selenium import webdriver
d = webdriver.Chrome()
d.get("https://www.imobiliare.ro/inchirieri-apartamente/sibiu/hipodrom-4/apartament-de-inchiriat-3-camere-X84T100B2?lista=2361394")
items = [item.get_attribute('innerText') for item in d.find_elements_by_xpath("//div[@class='titlu']")]
print(items)
d.quit()
answered Nov 25 '18 at 10:14
AnderssonAndersson
39.2k113769
39.2k113769
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.
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%2f53463974%2fpython-selenium-xpath-geting-text-is-empty%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