2017-02-28 47 views
-4

Facebook的post_box元素。我无法找到xpath的元素Facebook post_box元素。我找不到xpath的元素

嗨, 我学会在Python中使用Selenium Webdriver编写自动化测试脚本。我将制作“Facebook海报脚本”。登录后我想单击SendBox并发送一些文本,但我无法用Xpath对其进行身份验证。 Firebug不会帮助我们。 Thx寻求帮助。

事情是这样的:

后从萤火虫登录

newpost=driver.find_element_by_xpath("i dont know correct xpath") 
newpost.click() 
newpost.send_keys("Hello!") 
newpost.submit() 

的XPath不工作

newpost = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div[3]/div/div/div/div[2]/div[1]/div/div/div/div[2]/div/div[1]/div[1]/div[2]/div/div/div/div/div/div[2]/div/div/div/div") 
+0

坦白说我希望他们会做起来很他们的网站( Facebook)根本不适用于WebDriver,以防止漫游/垃圾邮件。因为我假设你不在Facebook上工作,如果你正在寻找要学习的网站试试这个:http://www.techbeamers.com/websites-to-practice-selenium-webdriver-online/ 或者如果你是创造机器人/垃圾邮件....我真的不希望你有太大的成功。 – jibbs

回答

0

正确的解决办法:

newpost = driver.find_element_by_css_selector("[name='xhpc_message']") 
newpost.click() 
newpost.send_keys("Hello!") 
newpost.submit() 

@GVi THX的帮助

0

首先,从来没有使用绝对的XPath - 它的维护成本高,看起来太可怕。

据我所知,你需要点击输入字段的占位符'你在想什么'。然后,您可以使用值为'status-attachment-mentions-input'的'data-testid'属性。

如果您确实需要使用xpath,请尝试以下操作: "//[@data-testid='status-attachment-mentions-input']"。您还可以使用CSS选择器,并找到这样哟元素:

inputField = driver.find_element_by_css_selector("[data-testid='status-attachment-mentions-input']") 
+0

不工作:( 文件 “d:/untitled/AllegroTest.py” 27行 newpost = driver.find_element_by_css_selector( “[数据testid =” 状态附着-提到输入 “]”) ^ 的SyntaxError :无效语法 过程结束,退出代码1个 为括号: 正确版本:driver.find_element_by_css_selector( “[数据testid = '状态附着-提到输入']”) 相同的错误等之前: 无法找到元素:[data-testid ='status-attachment-mentions-input'] – PythonLearn

+0

我会编辑一个答案。而不是双重的“状态 - 在tachment-mentions-in put”。 – vilkg

+0

像以前一样的错误: 无法找到元素:[data-testid ='status-attachment-mentions-input'] – PythonLearn