【发布时间】:2018-09-30 09:01:05
【问题描述】:
我正在尝试使用 Python 和 selenium webdriver 自动化流程。 我能够成功登录并导航到我想要发布内容的页面,但由于某种原因,系统无法识别 xpath。
它给出了以下错误:
NoSuchElementException:无法定位元素://*[@id="widecol"]/div/form/p[1]/input
这是我的代码:
from selenium import webdriver
mydriver = webdriver.Firefox()
mydriver.get("https://www.phishtank.com/")
mydriver.maximize_window()
mydriver.find_element_by_xpath('//*[@id="username"]').send_keys("myusername")
mydriver.find_element_by_xpath('//*[@id="password"]').send_keys("mypassword")
mydriver.find_element_by_xpath('//*[@id="header"]/div[2]/form/input[3]').click()
mydriver.find_element_by_xpath('//*[@id="nav"]/ul/li[2]/a').click()
mydriver.find_element_by_xpath('//*[@id="widecol"]/div/form/p[1]/input').send_keys("sample text testing to fill form")
这是我的 HTML 代码
<div id="widecol">
<div class="padded">
<form method="POST">
<h2>Add A Phish</h2>
<ol>
<li>Visit our <b><a href="what_is_phishing.php">What is phishing?</a></b> page to confirm that the suspected phish meets all of the criteria.</li>
<li>Add a phish using the form below, or even better, submit a phish directly <a href="mailto:phish@phishtank.com">via email</a>.</li>
</ol>
<h3>Phish URL:</h3>
<p>
<input type="text" name="phish_url" style="width:90%;" value="" /><br />
<span class="small">Copy and paste the URL of the phishing website.</span>
</p>
<h3>What is the organization referenced in the email?</h3>
<p class="slim">
<select name="phish_target">
这给了我以下错误:
NoSuchElementException:无法定位元素://*[@id="widecol"]/div/form/p[1]/input
这是 HTML 代码:
<input type="text" name="phish_url" style="width:90%;" value=""> outer HTML code
这是我的 XPath:
//*[@id="widecol"]/div/form/p[1]/input - Xpath
请告诉我去哪里找,谢谢。
【问题讨论】:
标签: python-3.x selenium selenium-webdriver xpath css-selectors