Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 选择网页上的按钮selenium VBA_Excel_Vba_Selenium - Fatal编程技术网

Excel 选择网页上的按钮selenium VBA

Excel 选择网页上的按钮selenium VBA,excel,vba,selenium,Excel,Vba,Selenium,我正在尝试自动化一个有大约50个选择按钮的网页,下面是一个例子 <input type="button" value="اختر" onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Select$2')"> 但我想选择特定按钮。如果您想使用onclick属性的唯一部分作为定位器,请尝试 //input[@type='button'

我正在尝试自动化一个有大约50个选择按钮的网页,下面是一个例子

<input type="button" value="اختر" onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Select$2')">

但我想选择特定按钮。

如果您想使用
onclick
属性的唯一部分作为定位器,请尝试

//input[@type='button' and contains(@onclick, 'Select$2')]

太神了谢谢。如何避免选择20、21和22等等,因为xpath也会选择它们?@YasserKhalil可能会尝试添加转义字符,如
contains(@onclick,\'Select$2\')
,以指定希望
onclick
属性正好包含字符串
'Select$2'
,而不是子字符串
Select$2
。。。我不知道如何在VBA中完成。在Python中,我们可以混合引号
'//input[@type=“button”和contains(@onclick,'Select$2'))
非常感谢。我可以用VBA解决这个问题。将变量
Dim sSel声明为字符串
,然后分配值
sSel=“'Select$2'”
,最后使用此行
bot.findelementbypath(//input[@type='button'和contains(@onclick,&sSel&'))。单击
//input[@type='button' and contains(@onclick, 'Select$2')]