0

Hi~in this music websit: Music website link i want to click on the like button in the right side of the song bar i use below codes:

like_number=3
like_pos=f'#app > div > div.content-wrapper > div.song-list-view.list-view.view-without-leftbar > div.song-list > div > div.table.idle.song-table.song-list-table > div > table > tbody > tr:nth-child({str(like_number)}) > td:nth-child(5) > div > div > div:nth-child(1) > div'
button = self.browser.find_element_by_css_selector(like_pos)
self.browser.implicitly_wait(10)
ActionChains(self.browser).move_to_element(button).click(button).perform()

But,there is no response,console shows that my the tag is not interactive:

element not interactable” exception

I am so confused ,cause i search for whole the stack overflow ,but there is no practical solution for me

I just want to achieve a simple function of clicking on like button Thanks if you have any great idea for me!

The hard thing is that you have to pause you mouse for a while and then click button shows ,so that you are able to click on it ,this is so wired situation.

Below is image example

image: Song bar activate when you move your mouse and pause for a while

image: The state when you click on the like love button

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Super-ilad
  • 101
  • 11
  • How about putting sleep after the mouse is moved over the button? Maybe it need some time to react? – marke Aug 14 '19 at 13:44
  • You probably need to move to some element that you can see first on the row, like the time or song title, and then you can click on the like button. Theory being that if the element isn't visible it might have not have a location and selenium doesn't know how to move to it. – mrfreester Aug 14 '19 at 14:30
  • Try to use Xpath way rather than Css way, i don't know why ,but it is practical. – Super-ilad Aug 15 '19 at 00:54

1 Answers1

0

To click() on the Like button in the right side of the song bar you have to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategies:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("start-maximized")
    driver = webdriver.Chrome(options=chrome_options)
    driver.get("https://www.xiami.com/favorite/88955424")
    ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//table/tbody/tr//div[@class='duration-container ops-container']")))).perform()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//table/tbody/tr//div[@class='duration-container ops-container']//div[@class='operations ops-right']/div[@class='ops-item']/div[@class='iconfont']"))).click()
    
  • Browser Snapshot:

like


References

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Yeah,I know, it can be done in Xpath, but it cant be done in Css,if you try to replace it with Css with right place, no response, maybe my original try is right but use Css, so wired... – Super-ilad Aug 15 '19 at 00:53