Tithibots / tithiwa

Automate Web WhatsApp with selenium in python.
MIT License
24 stars 22 forks source link

Created exit_from_groups() in Group class #44

Closed Vipul-Bajaj closed 3 years ago

Vipul-Bajaj commented 3 years ago

This PR fixes #43 Also, I have made a method _find_group() to find the group. This method can also be used in method _open_members_list(). The current way to search group, present in _open_members_list() lands to the wrong group if we have group names with common prefixes ike ABC, ABC1, ABC11.

NavpreetDevpuri commented 3 years ago

There is some bug

from tithiwa import Tithiwa

tithiwabot = Tithiwa()
# tithiwabot.session.generate_session()
tithiwabot.session.open_session()
tithiwabot.chatroom.send_message_to_number("919592140593", "Yess, from tithiwa")
tithiwabot.group.exit_from_groups(["Group made by tithiwa", "Group made by tithiwa1", "Group made by tithiwa2", "t", "t"])
tithiwabot.quit()

Output

Injecting session... ✔ Done
Opening chatroom to "919592140593"... ✔ Done
Sending message "Yess, from tithiwa" to number "919592140593"...... ✔ Done
Exiting from group "Group made by tithiwa"... ✘ Failed. Group not found.
Exiting from group "Group made by tithiwa1"... ✘ Failed. Group not found.
Exiting from group "Group made by tithiwa2"... ✘ Failed. Group not found.
Exiting from group "t"... ✘ Failed. Group not found.
Exiting from group "t"... ✘ Failed. Group not found.

ShareX_z30VK07uEi

NavpreetDevpuri commented 3 years ago

not found_group is always False even when found_group is having value See

found_group = self._find_group(group)
print(f'{not found_group}, {found_group}')

Output

False, <selenium.webdriver.remote.webelement.WebElement (session="34f6535f2fdc230396c7bb36f94af36a", element="e3696d4d-4e33-4b67-b3ae-ad4257b74d1a")>
NavpreetDevpuri commented 3 years ago

After exiting 1st group I think it got the deleting group's element because that group was deleting and the next group was still opening and when the previous group deleted then it says "Wait you don't have that element anymore"

Injecting session... ✔ Done
Exiting from group "Group made by tithiwa"... ✔ Done
Exiting from group "Group made by tithiwa1"... Traceback (most recent call last):
  File "F:/projects/tithiwa/tithiwa/temp1.py", line 12, in <module>
    tithiwabot.group.exit_from_groups(["Group made by tithiwa", "Group made by tithiwa1", "Group made by tithiwa2", "t", "t"])
  File "F:\projects\tithiwa\tithiwa\group.py", line 110, in exit_from_groups
    self._wait_for_an_element_to_be_clickable(SELECTORS.GROUPS.NAME).click()
  File "F:\projects\tithiwa\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "F:\projects\tithiwa\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "F:\projects\tithiwa\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "F:\projects\tithiwa\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
  (Session info: chrome=86.0.4240.75)
NavpreetDevpuri commented 3 years ago

I solved the above errors But now a similar error to https://github.com/Tithibots/tithiwa/issues/45 is appears


Traceback (most recent call last):
  File "F:/projects/tithiwa/tithiwa/temp1.py", line 12, in <module>
    tithiwabot.group.exit_from_groups(["Group made by tithiwa", "Group made by tithiwa1", "Group made by tithiwa2", "t", "t"])
  File "F:\projects\tithiwa\tithiwa\group.py", line 110, in exit_from_groups
    self._wait_for_an_element_to_be_clickable(SELECTORS.GROUPS.NAME).click()
  File "F:\projects\tithiwa\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "F:\projects\tithiwa\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "F:\projects\tithiwa\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "F:\projects\tithiwa\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div class="DP7CM">...</div> is not clickable at point (599, 18). Other element would receive the click: <div class="_3vTfY">...</div>
  (Session info: chrome=86.0.4240.75)
``
Vipul-Bajaj commented 3 years ago

Let me have a look

Vipul-Bajaj commented 3 years ago

not found_group is always False even when found_group is having value See

found_group = self._find_group(group)
print(f'{not found_group}, {found_group}')

Output

False, <selenium.webdriver.remote.webelement.WebElement (session="34f6535f2fdc230396c7bb36f94af36a", element="e3696d4d-4e33-4b67-b3ae-ad4257b74d1a")>

sorry for that, I forgot to reverse the condition

Vipul-Bajaj commented 3 years ago
from tithiwa import Tithiwa
tithiwabot = Tithiwa()
tithiwabot.session.open_session(sessionfilename="00")
tithiwabot.group.exit_from_groups(["Harry", "Sirius", "Sirius1", "ABC","Group made by tithiwa","Group made by tithiwa"])
tithiwabot.quit()

Output:

Injecting session... ✔ Done
Exiting from group "Harry"... ✔ Done
Exiting from group "Sirius"... ✔ Done
Exiting from group "Sirius1"... ✔ Done
Exiting from group "ABC"... ✘ Failed. Group not found.
Exiting from group "Group made by tithiwa"... ✔ Done
Exiting from group "Group made by tithiwa"... ✘ Failed. You are not the member of the group.

Process finished with exit code 0