Issue
Using Selenium's find_element(By.XPATH, "//tag[@class='classname']"
, when I try to iterate over elements of certain classes, I sometimes get this warning by Pycharm : "Expected 'collections.Iterable', got 'WebElement' instead". I don't understand why it would iterate over some classes with no problem and others not. Could it have something to do with the different tags?
In the code bellow, issues_available
is highlighted in green and displays the warning mentioned above.
code:
issues_available = driver.find_element(By.XPATH, "//div[@class='issue ember-view']")
currently_clicked_issue = driver.find_element(By.XPATH, "div[@class='issue active-override ember-view']")
issues_list = []
for issue in issues_available:
issue_vol_number = issue.find_element(By.XPATH, ".//span[@class='label']").text
///
Solution
When you write this
issues_available = driver.find_element(By.XPATH, "//div[@class='issue ember-view']")
Now issues_available
is a single web element.
and It makes no sense to iterate a single web element.
Instead, you should use :
find_elements
which will return a list of web elements.
So, your effective code will be :
issues_available = driver.find_elements(By.XPATH, "//div[@class='issue ember-view']")
currently_clicked_issue = driver.find_element(By.XPATH, "div[@class='issue active-override ember-view']")
issues_list = []
for issue in issues_available:
issue_vol_number = issue.find_element(By.XPATH, ".//span[@class='label']").text
Answered By - cruisepandey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.