Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this code

tcost = driver.find_element_by_id("MainContent_txtTotalCost").text
total = int(tcost)

It gives (ValueError: invalid literal for int() with base 10: '')

I need to convert text in text box to int to do some calculations over it and sure, If you have any suggestions to enhance the code please do.

share|improve this question
The int function should convert a valid string to an integer. Why do you think it fails? Have you tried printing/logging the string? – user246 Oct 16 '12 at 11:35
What language - Java ? – Phil Kirkham Oct 16 '12 at 11:35
@phil python language – engy Oct 16 '12 at 11:40
@user246 i tried print(tcost),it should print the value of the text box in the IDLE i'm using right?!,as it gave new empty line only and then >>> for next actions – engy Oct 16 '12 at 11:43
up vote 5 down vote accepted

You may need to use .get_attribute("value"). instead of .text.

share|improve this answer
it gives that error 'WebElement' object has no attribute 'value' – engy Oct 16 '12 at 12:10
.get_attribute("value") worked thaaaaaaaaaaanx – engy Oct 16 '12 at 12:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.