我是新手,试图通过在flipkart网站上搜索来制作第一个自动化测试用例,然后搜索手机并单击特定的手机,然后添加到购物车,但它不起作用,得到这个错误硒.common.exceptions.ElementClickInterceptedException:消息:元素点击拦截:元素...在点 (728, 232) 处不可点击。并尝试通过查找css选择器/ xpath / id /名称,它们都没有工作,但当我使用get方法调用dirct链接页面时,它的工作原理。任何帮助将不胜感激。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from time import sleep
driver = webdriver.Chrome('/usr/local/bin/chromedriver')
driver.get("https://www.flipkart.com/")
sleep(1)
print(" site title : "+driver.title)
btn=driver.find_element_by_xpath('//*[@class="_2KpZ6l _2doB4z"]')
btn.click()
search_bar = driver.find_element_by_name("q")
search_bar.clear()
search_bar.send_keys("mobiles")
search_bar.send_keys(Keys.RETURN)
print(" listing page ::")
sleep(1)
a_link = driver.find_element_by_xpath('//*[@id="container"]/div/div[3]/div[1]/div[2]/div[2]/div/div/div/a/div[2]/div[1]/div[1]')
a_link.click()
print(" main page : ")
sleep(3)
cart = driver.find_element_by_xpath('//*[@id="container"]/div/div[3]/div[1]/div[1]/div[2]/div/ul/li[1]/buttons')
cart.click()
这里有几个问题:
/*[@id=“container”]/div/div[3]/div[1]/div[2]/divs[2]/divs/div/div/a/div[2]/div[1]/div[1]
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
driver = webdriver.Chrome('/usr/local/bin/chromedriver')
wait = WebDriverWait(driver, 20)
driver.get("https://www.flipkart.com/")
sleep(1)
print(" site title : "+driver.title)
wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@class="_2KpZ6l _2doB4z"]"))).click()
search_bar = wait.until(EC.visibility_of_element_located((By.NAME, "q")))
search_bar.clear()
search_bar.send_keys("mobiles")
search_bar.send_keys(Keys.RETURN)
print(" listing page ::")
a_link = wait.until(EC.visibility_of_element_located((By.XPATH, "(//div[@class='_4rR01T'])[1]")))
a_link.click()
print(" main page : ")
sleep(0.4)
driver.switch_to.window(driver.window_handles[-1])
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button._3v1-ww"))).click()