i have a problem with getting a value from a html table.
This is the code of the part im trying to acces
<div class="cell el-tooltip" style="width: 108px;"> 1.07 </div>
Im trying to acces the value with xpath .
wait.until(EC.visibility_of_element_located(By.XPATH, "//*[@id='pane-bus-device-inverter']/div/div[1]/div/div/section/div[1]/div[3]/div[2]/div/div[3]/table/tbody/tr/td[7]/div"))
I end up getting a error: "TypeError: init() takes 2 positional arguments but 3 were given"
CodePudding user response:
Can I suggest that maybe you are using classes to identify a specific element, but there may be many elements using that class?
CodePudding user response:
This error
TypeError: init() takes 2 positional arguments but 3 were given"
is cause you are missing parenthesis ()
.
Instead of :
wait.until(EC.visibility_of_element_located(By.XPATH, "//*[@id='pane-bus-device-inverter']/div/div[1]/div/div/section/div[1]/div[3]/div[2]/div/div[3]/table/tbody/tr/td[7]/div"))
do this :
wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@id='pane-bus-device-inverter']/div/div[1]/div/div/section/div[1]/div[3]/div[2]/div/div[3]/table/tbody/tr/td[7]/div")))
Also this xpath
//*[@id='pane-bus-device-inverter']/div/div[1]/div/div/section/div[1]/div[3]/div[2]/div/div[3]/table/tbody/tr/td[7]/div
is absolute xpath, please use relative xpath or switch to css.
Relative xpath you can try :
//div[contains(@class,'is-scrolling-none')]//descendant::tbody/tr[1]/td[7]/div[contains(@class,'cell el-tooltip')]
or
//div[contains(@class,'is-scrolling-none')]//descendant::tbody/descendant::div[contains(@class,'cell el-tooltip')]
or
//div[contains(@class,'is-scrolling-none')]//descendant::div[contains(@class,'cell el-tooltip')]
PS : Please check in the dev tools
(Google chrome) if we have unique entry in HTML DOM
or not.
Steps to check:
Press F12 in Chrome
-> go to element
section -> do a CTRL F
-> then paste the xpath
and see, if your desired element
is getting highlighted with 1/1
matching node.
You can use CSS selector as well. But I need to have page url to give you more robust locator.