[英]How to click button available in dynamic web table using Selenium and Python
I am new to Selenium, I have gone through the website tutorialhttps://www.guru99.com/handling-dynamic-selenium-webdriver.html to learn how to get the row count & column count for the web table. I am new to Selenium, I have gone through the website tutorialhttps://www.guru99.com/handling-dynamic-selenium-webdriver.html to learn how to get the row count & column count for the web table.
But in our website testing we need to do a few more advanced operations.但是在我们的网站测试中,我们需要做一些更高级的操作。 The web table is similar to demo website http://demo.guru99.com/test/web-table-element.php .
web 表类似于演示网站http://demo.guru99.com/test/web-table-element.php 。
Questions:问题:
I have tried using the below code, but I am not able click and navigate the to corresponding screen.我尝试使用以下代码,但无法单击并导航到相应的屏幕。
try:
WebDriverWait(self.driver, 10).until(EC.presence_of_all_elements_located((By.TAG_NAME, 'td')))
table= self.driver.find_element(By.ID, 'TableGrid')
trs = table.find_elements_by_tag_name('tr')
for tr in trs:
tds = tr.find_elements_by_tag_name('td')
for td in tds:
match_obj = re.search('searching Text', td.text)
print(match_obj)
if match_obj and match_obj.group(1) == '0':
success_button = tr.find_element_by_css_selector('button.btn-success')
print(success_button.get_attribute('type'))
success_button.click()
except :
pass
OK.simply I am asking how to match particular value in any columns in the dynamic growing web table ( the row index is not fixed) and click the button available in the particular row of the first column? OK.simply 我问如何匹配动态增长 web 表(行索引不固定)中任何列中的特定值,然后单击第一列特定行中可用的按钮?
try:
WebDriverWait(self.driver, 10).until(EC.presence_of_all_elements_located((By.TAG_NAME, 'td')))
table= self.driver.find_element(By.ID, 'TableGrid')
trs = table.find_elements_by_tag_name('tr')
row_count = 0
matched_row_count = 0
for tr in trs:
tds = tr.find_elements_by_tag_name('td')
time.sleep(2)
for i, td in enumerate(tds):
# This for loop will iterate single row value. Here i is index value
if i == 1 and td.text == 'required matching column value':
#print("Matched {}: {}".format(i, td.text))
matched_row_count = row_count
print("matched_row_count :",matched_row_count)
row_count = row_count+1
# will print all the column name #//*[@id="TableGrid"]/div[1]/table/tbody/tr[4]/td[1]/a[3]
# tr[4] -row [td1]-column a[3]-button
except :
print("could not found the column details")
element = self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child("+matched_row_count+")"+" "+".btn-info")
actions = ActionChains(self.driver)
actions.move_to_element(element).perform()
element = self.driver.find_element(By.CSS_SELECTOR, "body")
actions = ActionChains(self.driver)
actions.move_to_element(element).perform()
self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child("+matched_row_count+")"+" "+".btn-info").click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.