python .click()无法正常工作 [英] python .click() not working
问题描述
我当前正在使用以下Python和Selenium版本:
I am currently using the following Python and Selenium versions:
Python343.4.3(v3.4.3:9b73f1c3e601,2015年2月24日,22:43:06)[MSC v.1600 32位(Intel)]
Python34 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06)[MSC v.1600 32 bit (Intel)]
硒版本2.53.2
我希望有人会知道答案.我要实现的目标是获取一个Facebook页面,将其滚动到尽可能远的位置,然后展开页面下方显示的所有评论",回复"和查看更多"链接.
I am hoping someone will know the answer to this. What i am trying to achieve is to take a Facebook page, scroll it as far as it goes, and then expand all the 'comments', 'replies' and 'See More' links that appear down the page.
到目前为止,我仅尝试使用查看更多"链接,但无法处理点击链接的过程.我认为我的基本知识告诉我,它找到xpath的原因是我没有收到此错误,但我为.click函数找到了它,此后立即调用.我也尝试过使用 find_element_by_link_text('See More')
,但这没有用.我还设法将html结构定位在查看更多"链接的两个示例所处的位置,但是由于它们不相同,因此我不确定如何实现这些示例:
So far I have only tried with the 'See More' links but I cannot get it to process clicking on the link. I think my basic knowledge tells me that it finds the xpath as i don't get an error for this but I do for the .click function which is called immediately after. I have also tried using find_element_by_link_text('See More')
however this didn't work. I also managed to locate the html structures where two examples of the See More links where located however as they weren't identical i wasn't sure how to implement these:
//div[3]/div[2]/div/span/span/a/span
//div[2]/div[2]/div/span/span/a/span
//div[@id='id_58591b7145b529535706885']/span/span/a/span
//div[@id='id_58591f8225af12f45796030']/span/span/a/span
如果任何人有任何建议,修正或其他选择,那么我将不胜感激.预先感谢,
If anyone has any suggestions or amendments or alternative options then i would be grateful to here them. Thanks in advance,
import os
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#Global Variables
target = "serena.xxxx.x"
username = "xxxxx@xxxxxx.com"
password = "xxxxxxxx"
#code block to log in user
def logmein():
search_box = driver.find_element_by_name('email')
search_box.send_keys(username)
search_box = driver.find_element_by_name('pass')
search_box.send_keys(password)
search_box.submit()
driver = webdriver.Firefox()
driver.get("https://www.facebook.com//")
logmein()
elm = driver.find_element_by_tag_name('html')
elm.send_keys(Keys.END)
time.sleep(2)
elm.send_keys(Keys.END)
time.sleep(2)
elm.send_keys(Keys.END)
time.sleep(2)
elm.send_keys(Keys.END)
time.sleep(2)
elm.send_keys(Keys.HOME)
# Initiates See More Open
SeeMore = driver.find_element_by_xpath("//a[@class='see_more_link']")
print("Found See More")
SeeMore.click()
print("Expand SeeMore option")
推荐答案
有帮助吗?
import os
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
#Global Variables
target = "..."
username = "..."
password = "..."
def logmein():
search_box = driver.find_element_by_name('email')
search_box.send_keys(username)
search_box = driver.find_element_by_name('pass')
search_box.send_keys(password)
search_box.submit()
driver = webdriver.Firefox()
driver.get("https://www.facebook.com//")
logmein()
SeeMore = WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.LINK_TEXT, 'See More...')))
print("Found See More")
time.sleep(2) # apparently there is some javascript execution that requires this sleep to be here.
SeeMore.click()
print("Expand SeeMore option")
很高兴看到提到的链接的屏幕截图.这样,我可以转到模拟Facebook页面,并确保它可以正常工作.
Would be great to see a screenshot of the mentioned link. This way I could go to an analog Facebook page and make sure it works.
这篇关于python .click()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!