【发布时间】:2022-10-03 01:19:23
【问题描述】:
我正在尝试在表中搜索类“itemavailable”的元素。如果它存在,则单击它,如果不存在则转到下一行并在列中再次搜索。
这是HTML代码。
我的搜索代码在这里点击这里。我已经计算了行和列,还构建了 FinalXpath
for t_row in range(2, (num_rows)):
for t_col in range (3, 4):
FinalXPath = before_XPath + str(t_row) + aftertd_XPath + str(t_col) + aftertr_XPath + "[@class='itemavailable']"
print(FinalXPath)
try:
if driver.find_element(By.XPATH,"FinalXPath"):
print("found")
avslot = driver.find_element_by_xpath(FinalXPath)
avslot.click()
slot_found = True
break
except NoSuchElementException:
print("not matched")
pass
输出如下。
//*[@id='slotsGrid']/tbody/tr[2]/td[3][@class='itemavailable']
not matched
//*[@id='slotsGrid']/tbody/tr[3]/td[3][@class='itemavailable']
not matched
//*[@id='slotsGrid']/tbody/tr[4]/td[3][@class='itemavailable']
not matched
//*[@id='slotsGrid']/tbody/tr[5]/td[3][@class='itemavailable']
not matched
//*[@id='slotsGrid']/tbody/tr[6]/td[3][@class='itemavailable']
not matched
//*[@id='slotsGrid']/tbody/tr[7]/td[3][@class='itemavailable']
not matched
//*[@id='slotsGrid']/tbody/tr[8]/td[3][@class='itemavailable']
not matched
//*[@id='slotsGrid']/tbody/tr[9]/td[3][@class='itemavailable']
not matched
//*[@id='slotsGrid']/tbody/tr[10]/td[3][@class='itemavailable']
not matched
有一场比赛,但不知道为什么它会通过它。
【问题讨论】:
-
你能分享一个指向那个页面的链接吗?
-
不可以分享页面,抱歉
-
就像现在一样,您的问题不符合最低可重现示例标准。
标签: python selenium selenium-webdriver