Selenium VBA 具有可变谓词循环的 XPath
Selenium VBA XPath with variable predicate loop
我希望在 Selenium 语法方面得到一些帮助 VBA。
我正在尝试使用变量谓词 'r' 抓取一些 table 日期来指定这样的行,但它不起作用。
当用整数值代替谓词时,代码确实有效 'r'[我认为谓词是环顾四周的正确词]所以我知道表达式正在寻找正确的东西。
For r = 2 To 4
ThisWorkbook.Sheets("Orders").Cells(r, 1).Value = bot.FindElementByXPath("//*[@id='ctl00_mainContent_ucOrdersList_dgOrders']/tbody/tr[r]/td[2]").Text
Next r
看起来应该是可以的。我找到了这个,但不确定它是什么语言或如何将其翻译成 Selenium VBA:
for (int i =1;i<rows.size();i++)
{
max= wd.findElement(By.xpath("html/body/div[1]/div[5]/table/tbody/tr[" + (i+1)+ "]/td[4]")).getText();
所以本质上我该怎么做
tr[" + (i+1)+ "]
Selenium 中的位 VBA?
提前致谢。
在你的循环中试试这个:
ThisWorkbook.Sheets("Orders").Cells(r, 1).Value = bot.FindElementByXPath("//*[@id='ctl00_mainContent_ucOrdersList_dgOrders']/tbody/tr[" & r & "]/td[2]").Text
使用 & 连接字符串。
这是关键位:"...tr[" & r & "]/td..."
有关在 vb here
中加入字符串的更多信息
对于 + 运算符,他们声明:
Although in principle the + sign is identical to the & concatenation
operator, it also doubles as the addition operator. Hence, as
Microsoft states:
When you use the + operator, you may not be able to determine whether
addition or string concatenation will occur. Use the & operator for
concatenation to eliminate ambiguity and provide self-documenting
code.
我希望在 Selenium 语法方面得到一些帮助 VBA。
我正在尝试使用变量谓词 'r' 抓取一些 table 日期来指定这样的行,但它不起作用。
当用整数值代替谓词时,代码确实有效 'r'[我认为谓词是环顾四周的正确词]所以我知道表达式正在寻找正确的东西。
For r = 2 To 4
ThisWorkbook.Sheets("Orders").Cells(r, 1).Value = bot.FindElementByXPath("//*[@id='ctl00_mainContent_ucOrdersList_dgOrders']/tbody/tr[r]/td[2]").Text
Next r
看起来应该是可以的。我找到了这个,但不确定它是什么语言或如何将其翻译成 Selenium VBA:
for (int i =1;i<rows.size();i++)
{
max= wd.findElement(By.xpath("html/body/div[1]/div[5]/table/tbody/tr[" + (i+1)+ "]/td[4]")).getText();
所以本质上我该怎么做
tr[" + (i+1)+ "]
Selenium 中的位 VBA?
提前致谢。
在你的循环中试试这个:
ThisWorkbook.Sheets("Orders").Cells(r, 1).Value = bot.FindElementByXPath("//*[@id='ctl00_mainContent_ucOrdersList_dgOrders']/tbody/tr[" & r & "]/td[2]").Text
使用 & 连接字符串。
这是关键位:"...tr[" & r & "]/td..."
有关在 vb here
中加入字符串的更多信息对于 + 运算符,他们声明:
Although in principle the + sign is identical to the & concatenation operator, it also doubles as the addition operator. Hence, as Microsoft states:
When you use the + operator, you may not be able to determine whether addition or string concatenation will occur. Use the & operator for concatenation to eliminate ambiguity and provide self-documenting code.