python多按钮是_在Python中单击具有相同类名的多个按钮

This a column in a table this column contains buttons, on pressing each buttons a pdf is downloaded

The buttons have the same class names and I want to click on all the buttons.

This is what I did, but it doesnt work:

addinfo = driver.find_element_by_class_name('btnAddInfo')

for x in addinfo:

if addinfo[x].is_displayed():

addinfo[x].click()

解决方案

Hi First get the reference of the parent container in which all these buttons reside and then you will have to get the button reference which you would like to click by passing unique parameters to the method which identities the button which you want to click

public IWebElement GetButtontoClick(IWebElement prObj, string propName, string propVlu)

{

IWebElement btnToClick = null;

try

{

//get the list of all buttons in the prObj

IList btnlList = prObj.FindElements(By.ClassName("xyz"));

//iterate through each button element and find the button you want to click

for (int i = 0; i < btnlList.Count; i++)

{

IWebElement btn = btnlList[i];

var btnPropValue = ((IJavaScriptExecutor)DriverContext.Driver).ExecuteScript("return arguments[0]."+ propName+"; ", btn);

if (propVlu == btnPropValue.ToString())

{

Console.WriteLine("You have found the button you want to click");

btnToClick = btn;

break;

}

}

}

catch (Exception)

{

throw;

}

return btnToClick;

}

How to call this method

//i know outerHTML is too big just for example sake i have give that you can provide any unique property name and unique property value which differentiates one button from other,outerHTML is one such property

IWebElement myButton = GetButtontoClick(prObj, "outerHtml", "outerHTMLValue")

Hope this works.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值