When EC.text_to_be_present_in_element times out, is there any way to see what text it found instead?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Regarding this "expected conditions" Selenium function:



WebDriverWait(driver, wait).until(
EC.text_to_be_present_in_element(locator, expected_text), 'error msg')


It's incredibly useful diagnostic information to know what text, if any, was present instead. I feel like this data must be accessible somehow, but I also don't see how it could be.



I tried adding it to the error msg string like so:



WebDriverWait(driver, wait).until(
EC.text_to_be_present_in_element(locator, expected_text),
'actual text found: {}'.format(driver.find_element(*locator).text)


but obviously that will fail if the element can't be found. I could add a try/except clause, but that's getting ugly fast.



I guess I could "extend" the EC function to add a logging line. That would work, though that seems a little wonky to me.



Any other ideas? Is there some Selenium trick I'm missing?










share|improve this question























  • This sounds like an X-Y problem. Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do?

    – DebanjanB
    Jan 3 at 5:50











  • @DebanjanB The first part is the problem. The second part is me trying to solve the problem and not coming up with anything good. If the first part wasn't 100% clear, the idea is that sometimes tests that are looking for text fail. Generally speaking, it's a very helpful first step to see what text, if any, the product was actually showing instead of the expected text. This is even more important when it's hard to reproduce the problem.

    – mblakesley
    Jan 3 at 6:08













  • And just in case it's still not 100% clear, if the element of interest appears only when it contains text of interest, then it's trivial - just wait for the element, then log its text. But when the element is always hanging around, and only sometimes has text of interest in it, then we have to use this WebDriverWait/EC thing above. And now we don't seem to have access to the element's actual text for logging.

    – mblakesley
    Jan 3 at 6:27













  • To summarize, if element can't be found is a concern then text_to_be_present_in_element is not the best fit expected conditions you are looking at.

    – DebanjanB
    Jan 3 at 6:34











  • Well, EC.text_to_be_present_in_element conveniently checks both at the same time, but I take your point. So it sounds like you support my first idea then, correct? And I guess I can put an EC.presence_of_element_located in front to avoid the scenario I was thinking of. That works okay.

    – mblakesley
    Jan 3 at 6:54




















0















Regarding this "expected conditions" Selenium function:



WebDriverWait(driver, wait).until(
EC.text_to_be_present_in_element(locator, expected_text), 'error msg')


It's incredibly useful diagnostic information to know what text, if any, was present instead. I feel like this data must be accessible somehow, but I also don't see how it could be.



I tried adding it to the error msg string like so:



WebDriverWait(driver, wait).until(
EC.text_to_be_present_in_element(locator, expected_text),
'actual text found: {}'.format(driver.find_element(*locator).text)


but obviously that will fail if the element can't be found. I could add a try/except clause, but that's getting ugly fast.



I guess I could "extend" the EC function to add a logging line. That would work, though that seems a little wonky to me.



Any other ideas? Is there some Selenium trick I'm missing?










share|improve this question























  • This sounds like an X-Y problem. Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do?

    – DebanjanB
    Jan 3 at 5:50











  • @DebanjanB The first part is the problem. The second part is me trying to solve the problem and not coming up with anything good. If the first part wasn't 100% clear, the idea is that sometimes tests that are looking for text fail. Generally speaking, it's a very helpful first step to see what text, if any, the product was actually showing instead of the expected text. This is even more important when it's hard to reproduce the problem.

    – mblakesley
    Jan 3 at 6:08













  • And just in case it's still not 100% clear, if the element of interest appears only when it contains text of interest, then it's trivial - just wait for the element, then log its text. But when the element is always hanging around, and only sometimes has text of interest in it, then we have to use this WebDriverWait/EC thing above. And now we don't seem to have access to the element's actual text for logging.

    – mblakesley
    Jan 3 at 6:27













  • To summarize, if element can't be found is a concern then text_to_be_present_in_element is not the best fit expected conditions you are looking at.

    – DebanjanB
    Jan 3 at 6:34











  • Well, EC.text_to_be_present_in_element conveniently checks both at the same time, but I take your point. So it sounds like you support my first idea then, correct? And I guess I can put an EC.presence_of_element_located in front to avoid the scenario I was thinking of. That works okay.

    – mblakesley
    Jan 3 at 6:54
















0












0








0








Regarding this "expected conditions" Selenium function:



WebDriverWait(driver, wait).until(
EC.text_to_be_present_in_element(locator, expected_text), 'error msg')


It's incredibly useful diagnostic information to know what text, if any, was present instead. I feel like this data must be accessible somehow, but I also don't see how it could be.



I tried adding it to the error msg string like so:



WebDriverWait(driver, wait).until(
EC.text_to_be_present_in_element(locator, expected_text),
'actual text found: {}'.format(driver.find_element(*locator).text)


but obviously that will fail if the element can't be found. I could add a try/except clause, but that's getting ugly fast.



I guess I could "extend" the EC function to add a logging line. That would work, though that seems a little wonky to me.



Any other ideas? Is there some Selenium trick I'm missing?










share|improve this question














Regarding this "expected conditions" Selenium function:



WebDriverWait(driver, wait).until(
EC.text_to_be_present_in_element(locator, expected_text), 'error msg')


It's incredibly useful diagnostic information to know what text, if any, was present instead. I feel like this data must be accessible somehow, but I also don't see how it could be.



I tried adding it to the error msg string like so:



WebDriverWait(driver, wait).until(
EC.text_to_be_present_in_element(locator, expected_text),
'actual text found: {}'.format(driver.find_element(*locator).text)


but obviously that will fail if the element can't be found. I could add a try/except clause, but that's getting ugly fast.



I guess I could "extend" the EC function to add a logging line. That would work, though that seems a little wonky to me.



Any other ideas? Is there some Selenium trick I'm missing?







python selenium






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 3:27









mblakesleymblakesley

174313




174313













  • This sounds like an X-Y problem. Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do?

    – DebanjanB
    Jan 3 at 5:50











  • @DebanjanB The first part is the problem. The second part is me trying to solve the problem and not coming up with anything good. If the first part wasn't 100% clear, the idea is that sometimes tests that are looking for text fail. Generally speaking, it's a very helpful first step to see what text, if any, the product was actually showing instead of the expected text. This is even more important when it's hard to reproduce the problem.

    – mblakesley
    Jan 3 at 6:08













  • And just in case it's still not 100% clear, if the element of interest appears only when it contains text of interest, then it's trivial - just wait for the element, then log its text. But when the element is always hanging around, and only sometimes has text of interest in it, then we have to use this WebDriverWait/EC thing above. And now we don't seem to have access to the element's actual text for logging.

    – mblakesley
    Jan 3 at 6:27













  • To summarize, if element can't be found is a concern then text_to_be_present_in_element is not the best fit expected conditions you are looking at.

    – DebanjanB
    Jan 3 at 6:34











  • Well, EC.text_to_be_present_in_element conveniently checks both at the same time, but I take your point. So it sounds like you support my first idea then, correct? And I guess I can put an EC.presence_of_element_located in front to avoid the scenario I was thinking of. That works okay.

    – mblakesley
    Jan 3 at 6:54





















  • This sounds like an X-Y problem. Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do?

    – DebanjanB
    Jan 3 at 5:50











  • @DebanjanB The first part is the problem. The second part is me trying to solve the problem and not coming up with anything good. If the first part wasn't 100% clear, the idea is that sometimes tests that are looking for text fail. Generally speaking, it's a very helpful first step to see what text, if any, the product was actually showing instead of the expected text. This is even more important when it's hard to reproduce the problem.

    – mblakesley
    Jan 3 at 6:08













  • And just in case it's still not 100% clear, if the element of interest appears only when it contains text of interest, then it's trivial - just wait for the element, then log its text. But when the element is always hanging around, and only sometimes has text of interest in it, then we have to use this WebDriverWait/EC thing above. And now we don't seem to have access to the element's actual text for logging.

    – mblakesley
    Jan 3 at 6:27













  • To summarize, if element can't be found is a concern then text_to_be_present_in_element is not the best fit expected conditions you are looking at.

    – DebanjanB
    Jan 3 at 6:34











  • Well, EC.text_to_be_present_in_element conveniently checks both at the same time, but I take your point. So it sounds like you support my first idea then, correct? And I guess I can put an EC.presence_of_element_located in front to avoid the scenario I was thinking of. That works okay.

    – mblakesley
    Jan 3 at 6:54



















This sounds like an X-Y problem. Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do?

– DebanjanB
Jan 3 at 5:50





This sounds like an X-Y problem. Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do?

– DebanjanB
Jan 3 at 5:50













@DebanjanB The first part is the problem. The second part is me trying to solve the problem and not coming up with anything good. If the first part wasn't 100% clear, the idea is that sometimes tests that are looking for text fail. Generally speaking, it's a very helpful first step to see what text, if any, the product was actually showing instead of the expected text. This is even more important when it's hard to reproduce the problem.

– mblakesley
Jan 3 at 6:08







@DebanjanB The first part is the problem. The second part is me trying to solve the problem and not coming up with anything good. If the first part wasn't 100% clear, the idea is that sometimes tests that are looking for text fail. Generally speaking, it's a very helpful first step to see what text, if any, the product was actually showing instead of the expected text. This is even more important when it's hard to reproduce the problem.

– mblakesley
Jan 3 at 6:08















And just in case it's still not 100% clear, if the element of interest appears only when it contains text of interest, then it's trivial - just wait for the element, then log its text. But when the element is always hanging around, and only sometimes has text of interest in it, then we have to use this WebDriverWait/EC thing above. And now we don't seem to have access to the element's actual text for logging.

– mblakesley
Jan 3 at 6:27







And just in case it's still not 100% clear, if the element of interest appears only when it contains text of interest, then it's trivial - just wait for the element, then log its text. But when the element is always hanging around, and only sometimes has text of interest in it, then we have to use this WebDriverWait/EC thing above. And now we don't seem to have access to the element's actual text for logging.

– mblakesley
Jan 3 at 6:27















To summarize, if element can't be found is a concern then text_to_be_present_in_element is not the best fit expected conditions you are looking at.

– DebanjanB
Jan 3 at 6:34





To summarize, if element can't be found is a concern then text_to_be_present_in_element is not the best fit expected conditions you are looking at.

– DebanjanB
Jan 3 at 6:34













Well, EC.text_to_be_present_in_element conveniently checks both at the same time, but I take your point. So it sounds like you support my first idea then, correct? And I guess I can put an EC.presence_of_element_located in front to avoid the scenario I was thinking of. That works okay.

– mblakesley
Jan 3 at 6:54







Well, EC.text_to_be_present_in_element conveniently checks both at the same time, but I take your point. So it sounds like you support my first idea then, correct? And I guess I can put an EC.presence_of_element_located in front to avoid the scenario I was thinking of. That works okay.

– mblakesley
Jan 3 at 6:54














0






active

oldest

votes












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015952%2fwhen-ec-text-to-be-present-in-element-times-out-is-there-any-way-to-see-what-te%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015952%2fwhen-ec-text-to-be-present-in-element-times-out-is-there-any-way-to-see-what-te%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith