L
L
lancerok2021-07-13 00:46:42
Python
lancerok, 2021-07-13 00:46:42

I can't click on the domain. Why?

In the mobile version, I can not click on the domain.
In the desktop version, everything is fine.

Tell me where to dig?

from selenium import webdriver
# мобильная эмуляция

WIDTH = 360
HEIGHT = 640
PIXEL_RATIO = 3.0
UA = 'Mozilla/5.0 (Linux; U; Android 10; ru-ru; Redmi Note 9 Build/QP1A.190711.020) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.141 Mobile Safari/537.36 XiaoMi/MiuiBrowser/12.4.4-g'
 
mobileEmulation = {"deviceMetrics": {"width": WIDTH, "height": HEIGHT, "pixelRatio": PIXEL_RATIO}, "userAgent": UA}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) # убоать палево
chrome_options.add_argument("--incognito")
chrome_options.add_experimental_option('mobileEmulation', mobileEmulation)

driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("http://www.yandex.ru")
search_string = driver.find_element_by_css_selector("input")
search_string.send_keys("Аудиосказки на ночь")
search_string.submit()

import time 
time.sleep(3)
test2 = driver.find_element_by_link_text("mishka-knizhka.ru").click() # Так не получается
test3 = driver.find_element_by_css_selector ("organic__subtitle * = 'mishka-knizhka.ru'").click() # Так тоже
test4 = driver.find_element_by_css_selector (".OrganicTitle-LinkText: contains ('mishka-knizhka.ru')").click() #И так
time.sleep(3)
driver.quit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gresaggr, 2021-07-20
@gresaggr

links = driver.find_elements_by_class_name('OrganicTitle-Link')
if links:
    for link in links:
        url = link.get_attribute('href')
        if 'mishka-knizhka.ru' in url:
            link.click()
            break

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question