Skip to main content
added 13 characters in body
Source Link
Alexey R.
  • 11.6k
  • 5
  • 20
  • 39

`#driver.find_element_by_xpath('//div[@id="groups"]/div/div/div/div/div[2]/div[1]/div/div/button').click() i = 5 gPath1 = str("'//div[@id="groups"]/div/div/div/div/div[2]/div[") gPath2 = str(i) gPath3 = str("]/div/div/button'") gPath = gPath1 + gPath2 + gPath3

driver.find_element_by_xpath(gPath).click()`

#driver.find_element_by_xpath('//div[@id="groups"]/div/div/div/div/div[2]/div[1]/div/div/button').click()
i = 5
gPath1 = str("\'//div[@id=\"groups\"]/div/div/div/div/div[2]/div[")
gPath2 = str(i)
gPath3 = str("]/div/div/button\'")
gPath = gPath1 + gPath2 + gPath3

driver.find_element_by_xpath(gPath).click()

I'm getting InvalidSelectorException error while using variable, but when i use the commented line it is working fine. Please help.

`#driver.find_element_by_xpath('//div[@id="groups"]/div/div/div/div/div[2]/div[1]/div/div/button').click() i = 5 gPath1 = str("'//div[@id="groups"]/div/div/div/div/div[2]/div[") gPath2 = str(i) gPath3 = str("]/div/div/button'") gPath = gPath1 + gPath2 + gPath3

driver.find_element_by_xpath(gPath).click()`

I'm getting InvalidSelectorException error while using variable, but when i use the commented line it is working fine. Please help.

#driver.find_element_by_xpath('//div[@id="groups"]/div/div/div/div/div[2]/div[1]/div/div/button').click()
i = 5
gPath1 = str("\'//div[@id=\"groups\"]/div/div/div/div/div[2]/div[")
gPath2 = str(i)
gPath3 = str("]/div/div/button\'")
gPath = gPath1 + gPath2 + gPath3

driver.find_element_by_xpath(gPath).click()

I'm getting InvalidSelectorException error while using variable, but when i use the commented line it is working fine. Please help.

Source Link

Variable in Xpath is not working

`#driver.find_element_by_xpath('//div[@id="groups"]/div/div/div/div/div[2]/div[1]/div/div/button').click() i = 5 gPath1 = str("'//div[@id="groups"]/div/div/div/div/div[2]/div[") gPath2 = str(i) gPath3 = str("]/div/div/button'") gPath = gPath1 + gPath2 + gPath3

driver.find_element_by_xpath(gPath).click()`

I'm getting InvalidSelectorException error while using variable, but when i use the commented line it is working fine. Please help.