我试图点击登录链接但系统会抛出noSuchElementException。 我也试过xpaths,但我无法点击登录按钮,我附加代码
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
class CreateAccount:
def signUp(self):
browser = webdriver.Firefox()
browser.get("http://www.scrumdo.com")
time.sleep(5)
browser.find_element_by_link_text("Login").click()
time.sleep(5)
browser.find_element_by_xpath("//a[@href='/account/signup']").click()
time.sleep(5)
browser.find_element_by_xpath("//input[@name='username']").send_keys("Rockyhandsome")
browser.find_element_by_xpath("//input[@name='fullname']").send_keys("Naqash Zafar")
browser.find_element_by_xpath("//input[@name='email']").send_keys("naqash.zafar@kualitatem.com")
browser.find_element_by_xpath("//input[@name='password']").send_keys("k12345678")
browser.find_element_by_xpath("//button[@type='submit']").click()
CA = CreateAccount()
CA.signUp()
追溯细节
Traceback (most recent call last):
File "C:/Users/naqash.zafar/PycharmProjects/Assignments/CreateAccountOnScrumdo.py", line 38, in <module> CA.signUp()
File "C:/Users/naqash.zafar/PycharmProjects/Assignments/CreateAccountOnScrumdo.py", line 15, in signUp browser.find_element_by_link_text("Login").click()
File "C:\Users\naqash.zafar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "C:\Users\naqash.zafar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 744, in find_element
{'using': by, 'value': value})['value']
File "C:\Users\naqash.zafar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "C:\Users\naqash.zafar\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"link text","selector":"Login"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///C:/Users/NAQASH~1.ZAF/AppData/Local/Temp/tmpiln2m889/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
at FirefoxDriver.prototype.findElement (file:///C:/Users/NAQASH~1.ZAF/AppData/Local/Temp/tmpiln2m889/extensions/fxdriver@googlecode.com/components/driver-component.js:10779)
at DelayedCommand.prototype.executeInternal_/h (file:///C:/Users/NAQASH~1.ZAF/AppData/Local/Temp/tmpiln2m889/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///C:/Users/NAQASH~1.ZAF/AppData/Local/Temp/tmpiln2m889/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///C:/Users/NAQASH~1.ZAF/AppData/Local/Temp/tmpiln2m889/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
Process finished with exit code 1
答案 0 :(得分:0)
您需要单击菜单下拉列表,然后选择登录按钮:
class CreateAccount:
def signUp(self):
browser = webdriver.Firefox()
browser.get("http://www.scrumdo.com")
menu = browser.find_element_by_xpath("//button[@class='navbar-toggle']")
menu.click()
time.sleep(.25)
menu.find_element_by_xpath("//li/a[@mixpanel='Homepage Clicked Login']").click()
browser.find_element_by_xpath("//a[@href='/account/signup']").click()
time.sleep(.25)
browser.find_element_by_xpath("//input[@name='username']").send_keys("Rockyhandsome")
browser.find_element_by_xpath("//input[@name='fullname']").send_keys("Naqash Zafar")
browser.find_element_by_xpath("//input[@name='email']").send_keys("naqash.zafar@kualitatem.com")
browser.find_element_by_xpath("//input[@name='password']").send_keys("k12345678")
browser.find_element_by_xpath("//button[@type='submit']").click()
答案 1 :(得分:0)
该页面包含一些需要与服务员同步的动态内容。 此外,您需要设置窗口的大小,因为布局的类型可能会根据宽度而变化:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import WebDriverException
browser = webdriver.Firefox()
wait = WebDriverWait(browser, 20)
browser.set_window_size(1280, 768)
browser.get("http://www.scrumdo.com")
# click login
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[.='Login']"))).click()
# wait for the login button
wait.until(EC.presence_of_element_located((By.ID, "loginButton")))
# click signup
browser.find_element_by_css_selector("a[href='/account/signup']").click()
# wait for the signup form
wait.until(EC.presence_of_element_located((By.ID, "signupForm")))
# fill the form
browser.find_element_by_css_selector("input[name=username]").send_keys("name")
browser.find_element_by_css_selector("input[name=fullname]").send_keys("password")
browser.find_element_by_css_selector("input[name=email]").send_keys("na@na.na")
browser.find_element_by_css_selector("input[name=password]").send_keys("na")
browser.find_element_by_css_selector("button[type=submit]").click()