无法使用xpath查找元素

nr7wwzry  于 2021-09-08  发布在  Java
关注(0)|答案(2)|浏览(327)

在firefox和python上使用selenium,我无法在网站上找到元素并在其中插入数值。
我正在使用firefox插件获取输入字段的xpath,我收到:
/html/body/div1/section/div/div/div/form/div1/div/div/div[4]/div2/div/div/div/div1/div1/table/tbody/tr1/td3/div/input
然而,对于python代码objdriver.find_element_by_xpath(“…”)-我收到“无法定位元素:”->like xpath是错误的
如果我在输入字段的边框上使用它,我会得到以下xpath:
/html/body/div1/section/div/div/div/form/div1/div/div/div[4]/div2/div/div/div/div1/div1/table/tbody/tr1/td3
我可以使用objdriver分配这个元素。通过xpath(“…”)查找元素,但它不是输入字段,所以我不能插入值
如果我在firefox中单击“检查”,我会得到:
css路径:

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部分:

<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>

你知道我怎样才能找到我需要的场地吗?
输入字段的一般视图:

获取边框的xpath时:

获取输入字段的xpath时:

lg40wkob

lg40wkob1#

你能试试下面的吗 xpath 具有 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')

进口:

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

gpnt7bae2#

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

相关问题