1
votes

I can't locate element on website and insert numerical value inside using Selenium on Firefox with Python.
  1. I am using firefox add-in to get the xPath for the input field, I receive:

    /html/body/div1/section/div/div/div/div/form/div1/div/div[4]/div2/div/div/div/div1/div1/table/tbody/tr1/td3/div/input

however with Python code objDriver.find_element_by_xpath("...") - I receive "Unable to locate element:" -> like xpath is wrong

  1. If I use it on the let's say border of the input field, I get following xPath:

    /html/body/div1/section/div/div/div/div/form/div1/div/div[4]/div2/div/div/div/div1/div1/table/tbody/tr1/td3

This element I can allocate using objDriver.find_element_by_xpath("...") but it is not input field, so I can't insert value

  1. If I click "Inspect" in Firefox, I get:

CSS Path:

html body div.main-content section.section div.block-one_col_1 div.container-fluid.wrapper div.row div.col-12 form#id_form-process.form-horizontal.formfactory div.row div.col-md div#fieldgroup_variants.fieldset div#fieldgroup_variants__fields.fieldset__content div.form-group.row.formfield_variantsCalculator.fieldpk_2533.mb-0.is-valid div.col-md-6.col-12 div.d-flex.flex-row div.w-100 div.table-scroll table.table.table--step tbody#tableContent.table tr.table-row.table-row--count td div.form-group.group1 input.form-control.variant-value.variant1.touched

xPath:

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

HTML part I am interested in:

<td data-risk="6.1"><div class="form-group group1" data-excluded="false" data-risk="6.1"><input name="1" class="form-control variant-value variant1 touched" data-editable="true" data-risk="6.1" data-visible-sum="true" data-dynamic="false"></div></td>

Do you have any idea how can I locate the field I need?
General view of Input field:

General view on input field

When getting xPath of the border:

selection xPath of border

When getting xPath of the Input field:

Sole Input field, xPath

2
I'd target the name... something like //input[contains(@name, "1")]... or name="1"pcalkins

2 Answers

1
votes

Can you try with the below xpath with Explicit waits :

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@name= '1' and contains(@class, 'variant-value')]"))).send_keys('10000')

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
0
votes

Try with xPath = //input[@class="form-control variant-value variant1 touched"][@id="1"]