selenium - RSelenium: replacing xpath with variable in R -


i try replace xpath in below code variable in r. (i'm doing because use loop.

> webelem <- remdr$findelement(using = 'xpath' ,      '//*[@id="dashboard-table-body"]/tr[3]') 

i create variable in r shown below.

a <- paste0("'" , "/" , "/*" , "[@id=" , '"dashboard-table-body"' ,"]" , "/tr[",3,"]")      > [1] "'//*[@id=\"dashboard-table-body\"]/tr[3]" 

output using variable input.

webelem3 <- remdr$findelement(using = 'xpath' , a) error:   summary: invalidselector          detail: argument invalid selector (e.g. xpath/css).          class: org.openqa.selenium.invalidselectorexception 

but works.

webelem3 <- remdr$findelement(using = 'xpath' ,  '//*[@id="dashboard-table-body"]/tr[3]') 

you have extra single quote @ beginning making expression invalid:

"'//*[@id=\"dashboard-table-body\"]/tr[3]"  ^here 

demo chrome console:

> $x("'//*[@id=\"dashboard-table-body\"]/tr[3]") vm11825:215 uncaught domexception: failed execute 'evaluate' on 'document': string ''//*[@id="dashboard-table-body"]/tr[3]' not valid xpath expression.(…)$x @ vm11825:215bound @ vm11825:18(anonymous function) @ vm11832:1 > $x("//*[@id=\"dashboard-table-body\"]/tr[3]") [] 

Comments