Selenium webdriver 如何为新生成的数据处理动态xpath?

Selenium webdriver 如何为新生成的数据处理动态xpath?,selenium-webdriver,xpath,pycharm,Selenium Webdriver,Xpath,Pycharm,我正在使用PyCharm和Selenium(Python)自动化一个网页,我在其中创建一个数据,创建数据后,我想编辑/更新/删除数据。在我的例子中,edit元素的xpath是relXPath=//tr[{Digits}]//td[4]//a[1],其中{Digits}即行id值不断变化,它可能会根据业务需求增加或减少。delete元素relxpath=//tr[{Digits}]//td[5]//a[1]也是如此 我试图实现的是,我想单击edit和delete元素,这只能使用上面提到的XPath

我正在使用PyCharm和Selenium(Python)自动化一个网页,我在其中创建一个数据,创建数据后,我想编辑/更新/删除数据。在我的例子中,edit元素的xpath是
relXPath=//tr[{Digits}]//td[4]//a[1]
,其中
{Digits}
即行id值不断变化,它可能会根据业务需求增加或减少。delete元素
relxpath=//tr[{Digits}]//td[5]//a[1]
也是如此

我试图实现的是,我想单击edit和delete元素,这只能使用上面提到的XPath实现(其中表行ID是动态变化的)。 除了这两个元素外,没有其他元素可以单击,也不能对我创建的记录/数据进行任何更改。那么,是否可以为创建的记录/数据列表处理表的动态行ID? 因为我不允许分享照片,但我可以分享以下细节:

我为编辑元素获得的属性有:

<a class="coral-Link coral-Link--subtle" href="/lucent/service_detail_types/292/edit" style=""><i class="coral-Icon coral-Icon--sizeXS coral-Icon--edit"></i></a>
<a class="coral-Link coral-Link--subtle coral-Form-fielderror" data-confirm="Are you sure you want to delete this?" data-method="delete" href="/lucent/service_detail_types/292" rel="nofollow" xpath="1"><i class="coral-Icon coral-Icon--sizeXS coral-Icon--delete"></i></a>

我为Delete元素获得的属性有:

<a class="coral-Link coral-Link--subtle" href="/lucent/service_detail_types/292/edit" style=""><i class="coral-Icon coral-Icon--sizeXS coral-Icon--edit"></i></a>
<a class="coral-Link coral-Link--subtle coral-Form-fielderror" data-confirm="Are you sure you want to delete this?" data-method="delete" href="/lucent/service_detail_types/292" rel="nofollow" xpath="1"><i class="coral-Icon coral-Icon--sizeXS coral-Icon--delete"></i></a>


…您没有问任何问题。每当我在表中创建新数据时,我关心的是获取“{Digits}”值。如果您这样做
//tr//td[4]//a[1]
?您将获得所有此类
元素的列表,并可以自由选择一个,例如最后一个。不,它不会选择任何值或元素。我的测试将跳过该命令行,转到下一个抛出错误的命令行,该错误表示“没有找到这样的xpath”,如果没有更多上下文,很难判断。也许您的XPath是错误的。也可能是这些元素是在页面加载后的某个时刻由Javascript创建的,而您等待的时间不够长。