-2

How can I find this element using Selenium? (I want to find it by the "data-peer-id" thing,)

<a class="row no-wrap row-with-padding row clickable hover-effect chat;ist-chat chatlist0chat-abitbigger" data-peer-id="-1280177577">

skrvt
  • 7
  • 1
  • 4
  • Does this answer your question? [Is there a way to find an element by attributes in Python Selenium?](https://stackoverflow.com/questions/28426645/is-there-a-way-to-find-an-element-by-attributes-in-python-selenium) – zaki98 Jan 07 '23 at 22:19
  • `selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (185, 851). Other element would receive the click: ` it gives me this error, and when I try `popup popup-forward active` by class name ofc It says that it's unable to locate it. – skrvt Jan 07 '23 at 23:01
  • Please [edit] to convert your images of text into actual text. [See here](https://meta.stackoverflow.com/a/285557/11107541) for why. See [/editing-help](/editing-help#code) for how to format code blocks. – starball Jan 08 '23 at 08:41
  • Sure thing, fixed it – skrvt Jan 08 '23 at 10:17

1 Answers1

1

To find the specific element for the telegram channel to forward the message to you would could do something like this:

from selenium.webdriver.common.by import By

driver.find_element(By.CLASS_NAME, 'popup-container').find_element(By.XPATH, '//*[@data-peer-id="-1280177577"]').click()

Source

This is because there are two sets of lists of channels (the sidebar and the new popup) when you originally searched you were getting the first instance (which would be the sidebar for channel selection) while the element that you want is the second instance of it (in the forward popup).

Though if you know the channel names beforehand on who you want to message you could just write the channel in the forward input box

driver.find_element(By.CLASS_NAME, 'popup-container').find_element(By.TAG_NAME, 'input').send_keys('channel_name_here')
Andrew Ryan
  • 1,489
  • 3
  • 15
  • 21
  • `selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (185, 851). Other element would receive the click: ` it gives me this error, and when I try `popup popup-forward active` by class name ofc It says that it's unable to locate it. – skrvt Jan 07 '23 at 23:01
  • @skrvt could you give more info such as the link to address how to best click the element that you want? Further `driver.find_element(By.CLASS_NAME, 'popup popup-forward active')` will not work in general because each of the names separated by a space is a difference class name attribute, which CLASS_NAME does not search for all of the attributes. You would have to only search by one of those that have a name. See above change in answer. – Andrew Ryan Jan 07 '23 at 23:43
  • Go to your Telegram Channel and click the Forward button under the message. After u have clicked it open up inspect element and click on the first channel. Each channel has the same class name, but only the "data-peer-id" is different. Please look at it yourself and maybe you'll know the answer. – skrvt Jan 08 '23 at 10:12
  • Also took a look at the seconds code you've sent me and it gives me this error: `selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".popup-forward"}` – skrvt Jan 08 '23 at 10:19