Selenium Python

问题描述 投票:0回答:1

我是Selenium Python的新手,正在一些网站上练习这些概念。我遇到了以下问题。

  1. 当我打开此网站(https://www.shoppersstop.com/)并单击品牌时,我会弹出Cookie:

    We use cookies to give you the best experience and analyze the site use. By continuing your browsing, you accept their use.
    
    Find out more about cookies in Privacy Policy.
    

任何人都可以帮助我,尽管它没有警报,但我如何关闭它?

  1. 当我将鼠标悬停在hautecurry上时,只有我可以看到必须单击的“立即查看”按钮。有人可以帮我吗?

下面是我到目前为止尝试过的代码:

  1. 用于关闭Cookie弹出窗口:

    wait = WebDriverWait(driver, 10)
    wait.until(expected_conditions.presence_of_element_located((By.CLASS_NAME, "closecookieExitButton")))        
    driver.find_element_by_class_name("close cookieExitButton").click()
    

我已经使用了元素的存在,也可以单击元素但是它没有关闭。

  1. 用于单击“立即查看”按钮,该按钮仅在鼠标悬停时可见:

    action = ActionChains(driver)
    viewNow = driver.find_element_by_xpath("//a[@href='/haute-curry']/span")
    action.move_to_element(viewNow).perform()
    viewNow.click()
    

尽管我的自定义xpath是唯一的,但没有发现任何元素异常。

python selenium xpath css-selectors webdriverwait
1个回答
0
投票

find_element_by_class_name()仅支持一个类名。

尝试使用CSS选择器:

driver.find_elements_by_css_selector(".close .cookieExitButton")

关于您的第二个问题,我无法在网站上找到有关hautecurry的内容,但首先获取该元素,然后将其悬停,应该反过来。

© www.soinside.com 2019 - 2024. All rights reserved.