4

I have this code:

tcost = driver.find_element_by_id("MainContent_txtTotalCost").text
total = int(tcost)
driver.find_element_by_id("MainContent_txtVisa").send_keys(total/2)
driver.find_element_by_id("MainContent_txtCash").send_keys(total/2)

It throws this error:

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.

alecxe
11.4k11 gold badges52 silver badges107 bronze badges
asked Oct 16, 2012 at 11:02
4
  • The int function should convert a valid string to an integer. Why do you think it fails? Have you tried printing/logging the string? Commented Oct 16, 2012 at 11:35
  • What language - Java ? Commented Oct 16, 2012 at 11:35
  • @phil python language Commented Oct 16, 2012 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 Commented Oct 16, 2012 at 11:43

1 Answer 1

6

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

answered Oct 16, 2012 at 12:09
2
  • it gives that error 'WebElement' object has no attribute 'value' Commented Oct 16, 2012 at 12:10
  • .get_attribute("value") worked thaaaaaaaaaaanx Commented Oct 16, 2012 at 12:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.