为了使用 Selenium 自动化浏览器中的某些任务,我需要识别网站上的某个字段并单击它。因为我用来识别正确字段的值可以显示多次,所以我正在遍历包括多个条件的结果。也许代码编写得无效,但条件 - 以定位正确的 x 和 y 坐标为目标。我想知道我是否可以以某种方式修改 location['x'] 值以执行单击命令。
# finding the X Value
tempmatchesx = driver.find_elements_by_xpath("//*[text()='" + tempoa + "']")
tempmatchesxVal =''
if indicator == '1':
for i in tempmatchesx:
if (i.location['x'] >= temptype['x']) and (i.location['y'] >= temptype['y']) and (i.location['x'] < temptypeoppo['x']):
tempmatchesxVal = i.location['x']
break
elif indicator == '2':
for i in tempmatchesx:
if (i.location['x'] >= temptype['x']) and (i.location['y'] >= temptype['y']) and (i.location['x'] > temptypeoppo['x']):
tempmatchesxVal = i.location['x']
break
# finding the Y Value
tempmatchesy = driver.find_elements_by_xpath("//*[text()='" + tempgoals + "']")
tempmatchesyVal =''
if indicator == '1':
for i in tempmatchesy:
if (i.location['x'] >= temptype['x']) and (i.location['y'] >= temptype['y']) and (i.location['x'] < temptypeoppo['x']):
i.location['x'] = tempmatchesxVal
i.click()
break
elif indicator == '2':
for i in tempmatchesy:
if (i.location['x'] >= temptype['x']) and (i.location['y'] >= temptype['y']) and (i.location['x'] > temptypeoppo['x']):
i.location['x'] = tempmatchesxVal
i.click()
所以基本上我的问题所指的部分如下:
i.location['x'] = tempmatchesxVal
i.click()
在一次迭代中,是否有可能用之前确定的 x 值 (tempmatchesxVal) 替换 location-X 值?或者我的工作方式是否可行并且失败(没有错误代码)可能在其他地方?目前,没有任何项目被点击。
更新:
整体的目的是单击一个我现在不知道内容的元素,因此我不能简单地搜索它。在那里我确定了元素被涂敷的列和行。
两个“find_elements_by_xpath”使用不同的输入完成 - 第一个是tempoa来识别列(x 值),第二个是行的tempgoals(y 值)。
显然我无法修改 i.location[coordinate] - 然后如何单击该元素?
一只斗牛犬
叮当猫咪
相关分类