简体   繁体   English

Python Selenium 按钮没有被点击

[英]Python Selenium button isn't being clicked

I am trying to scrape data from this website ( https://www.ilcollege2career.com/#/ ) using python (selenium and beautiful soup).我正在尝试使用 python (硒和美丽的汤)从该网站( https://www.ilcollege2career.com/#/ )中抓取数据。

The code I have is this:我的代码是这样的:

driver = webdriver.Chrome('my file path')

driver.get('https://www.ilcollege2career.com/#/')

first_click = WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tutorial-modal"]/div/div/div/div[3]/button[1]')))
first_click.click()

second_click = WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tutorial-start-modal"]/div/div/div[2]/div[2]')))
second_click.click()

So my problem is that while the first click works and it goes to the tutorial step the second click which will close the tutorial doesn't click.所以我的问题是,当第一次点击有效并且进入教程步骤时,第二次点击将关闭教程并没有点击。 For some reason time.sleep() works but I don't want to have to keep repeating that every step.由于某种原因 time.sleep() 有效,但我不想在每一步都重复这一点。 Am I doing something wrong?难道我做错了什么?

I have also tried find element by css as well.我也尝试过通过 css 查找元素。

Thank you.谢谢你。

The xpath to the second_click is not accurate in the sense that it does not send the click to correct element.到 second_click 的 xpath 是不准确的,因为它不会将点击发送到正确的元素。 try this out,试试这个,

driver.fullscreen_window()

driver.get('https://www.ilcollege2career.com/#/')

first_click = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tutorial-modal"]/div/div/div/div[3]/button[1]')))
first_click.click()

Option#1 -选项#1 -

second_click = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//button[@onclick='closeTutorial()']")))
second_click.click()

Option#2 -选项#2 -

second_click = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//div[@onclick='closeTutorial()']")))
second_click.click()

I found the solution to those who are looking for it.我为那些正在寻找它的人找到了解决方案。

invisible = WebDriverWait(driver, 10).until(EC.invisibility_of_element_located((By.ID, 'tutorial-modal')))

if invisible:

There was something running behind that wouldn't close out so I was never able to close that and by doing this I was able to exit out.后面有东西跑,不会关闭,所以我永远无法关闭它,通过这样做,我能够退出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM