1

I am preparing a program that reads values from a time sheet. I am using python 3 and selenium using Chrome webdriver.

I have been able to use the .text method to capture the text values in the first three columns (Time Entry,Category, and Totals). However, using the same method does not work on the input boxes starting in column 4 through to.

enter image description here

Here is the xpath for the first row, fourth column.

/html/body/form/table/tbody/tr/td/table/tbody/tr[2]/td[2]/table[3]/tbody/tr/td[2]/div/table[1]/tbody/tr/td/table[1]/tbody/tr[1]/td[1]/input

Here is the html for the first row, fourth column (with value 7)

<input name="grdDaysProjects$ctl02$txtPrjCol0" type="text" value="7" maxlength="5" readonly="readonly" id="grdDaysProjects_ctl02_txtPrjCol0" class="GridInputsShort" onblur="GetTotalRow('1','grdComboProjects_ctl02_lblHours',2,6,'grdDaysProjects'); VerticalSum(0,'grdTotal',2,1,0); AntiXSS('grdDaysProjects_ctl02_txtPrjCol0')" data-origvalue="7">

Here is the html for the second row, fourth column (with no value)

<input name="grdDaysProjects$ctl03$txtPrjCol0" type="text" maxlength="5" readonly="readonly" id="grdDaysProjects_ctl03_txtPrjCol0" class="GridInputsShort" onblur="GetTotalRow('1','grdComboProjects_ctl03_lblHours',3,6,'grdDaysProjects'); VerticalSum(0,'grdTotal',2,1,0); AntiXSS('grdDaysProjects_ctl03_txtPrjCol0')" data-origvalue="">

It should extract a text value of 7 while any blank cells should extract a zero or null value. Using the .text method with the find_element_by_xpath method results in only null values. The html has the value in two places, the "value" and "data-origvalue". When the value is null, the "value" variable does not appear in the html but the "data-origvalue" does. Any suggestions on getting the value from the "data-origvalue" using selenium?

4
  • 1
    Xpath with [1]... [3] (etc) are realy bad idea Commented Dec 20, 2019 at 15:44
  • It will be good if you post the relevant HTML so that valid xpath would be provided as part of solutions.Please note you have provided HTML for only input tag I am requesting for Table HTML as well. Commented Dec 20, 2019 at 15:48
  • @Wonka Could you please suggest a better way or point to another thread that I can check out for a preferred method? Appreciate the guidance, thanks! Commented Dec 20, 2019 at 16:02
  • @cookiemnstr247 lookup for item class, id or even contains text. You didnt post html, here and example "//input[contains(@name, 'grdDaysProjects')]" Commented Dec 20, 2019 at 16:07

1 Answer 1

1

Input tag having attribute value Try to fetch that value using element.get_attribute("value")

element=driver.find_element_by_xpath("your xpath")
print(element.get_attribute("value"))
Sign up to request clarification or add additional context in comments.

2 Comments

If this not resolved your problem then you need to post HTML of table as well to diagnose the problem.
Perfect, just what I was looking for. I just searched the doc page for that method and will look into it further as well. Thanks!

Your Answer

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.