Firefox61.01 64位(python3.6-32位)中的Selenium属性错误怎么处理?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (130)

我的程序基本上可以完成所有的工作,直到分配给字段时出现问题为止。我看不出代码有什么问题。完全相同的字段类型分配组,由编写的代码填充。为什么这里会有问题?

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

base_url =  "https://xxxxservice-now.com/login.do"

driver = webdriver.Firefox()
driver.implicitly_wait(10)



# INC CREATE WITH SAVE AND STAY

driver.get(base_url)
username = driver.find_element_by_id("user_name")
username.send_keys("admin")

time.sleep(1)


password = driver.find_element_by_id("user_password")
password.send_keys("xxxx")

time.sleep(1)

loginBtn = driver.find_element_by_id("sysverb_login")
loginBtn.click()

time.sleep(1)
#driver.implicitly_wait(5)

#driver.switch_to_frame("gsft_main")
createnew = driver.find_element_by_id("filter")
createnew.send_keys("Create New")
time.sleep(3)
createnew.send_keys(Keys.RETURN)

driver.switch_to_frame("gsft_main")


category = driver.find_element_by_name("incident.category")
#category = driver.find_element_by_id("incident.category")
category.send_keys("Software")
time.sleep(2)

subcategory = driver.find_element_by_id("incident.subcategory")
subcategory.send_keys("Email")
time.sleep(1)

time.sleep(2)
callerbox = driver.find_element_by_id("sys_display.incident.caller_id")
callerbox.send_keys("Abraham Lincoln")
callerbox.send_keys(Keys.RETURN)
time.sleep(1)

contacttype = driver.find_element_by_id("incident.contact_type")
contacttype.send_keys("Email")
time.sleep(1)

impact = driver.find_element_by_id("incident.impact")
impact.send_keys("2")
time.sleep(1)

urgency = driver.find_element_by_id("incident.urgency")
urgency.send_keys("2")
time.sleep(1)

assign_grp = driver.find_element_by_id("sys_display.incident.assignment_group")
assign_grp.send_keys("Database")

#assign_grp.click()
time.sleep(1)

short_desc = driver.find_element_by_id("incident.short_description")
short_desc.send_keys("This is an automated test!!")
time.sleep(1)

desc = driver.find_element_by_id("incident.description")
desc.send_keys("Here are some notes")
time.sleep(1)

#driver.find_element_by_id("sysverb_update_and_stay").click() 
#driver.find_element_by_id("sysverb_insert").click()

button = driver.find_element(By.XPATH, '/html/body/div[1]/span/span/nav/div/div[1]/button[2]')
button.click()
save_btn = driver.find_element(By.XPATH, '/html/body/div[7]/div[2]')
save_btn.click()
#button.send_keys(Keys.RETURN)
#time.sleep(3)


select = Select(driver.find_element_by_name("incident.state"))
select.select_by_visible_text("In Progress")
time.sleep(1)

assigned_to = driver.find.element(By.XPATH, '//*[@id="sys_display.incident.assigned_to"]')
assigned_to.send_keys("Beth Anglin")
time.sleep(1)
"""
assigned_to = driver.find.element_by_name("sys_display.incident.assigned_to")
assigned_to.send_keys("Beth Anglin")
time.sleep(1)
"""

time.sleep(1)
button = driver.find_element(By.XPATH, '/html/body/div[1]/span/span/nav/div/div[1]/button[2]')
button.click()
button.send_keys(Keys.RETURN)

输出

回溯(最近一次调用):文件“C:/USERS/HASAY/GoogleDrive/Selenium/Firefox_大公司_创造_存钱_Stay.py“,第100行,赋值_to=driver.find.Element(By.XPATH,‘/)*@id=“sys_显示.偶然.分配_致“‘)AttributeError:’Webriver‘对象没有属性’find‘

提问于
用户回答回答于

我想你可能打字上出现了错误。

而不是这个:(找到后点)

assigned_to = driver.find.element_by_name("sys_display.incident.assigned_to")

应该是:(下划线)

assigned_to = driver.find_element_by_name("sys_display.incident.assigned_to")
用户回答回答于

方法名称(即find.element)是不对的。尝试如下:

assigned_to = driver.find_element(By.XPATH, '//*[@id="sys_display.incident.assigned_to"]')
assigned_to.send_keys("Beth Anglin")

所属标签

可能回答问题的人

  • HKC

    红客学院 · 创始人 (已认证)

    26 粉丝7 提问5 回答
  • 西风

    renzha.net · 站长 (已认证)

    9 粉丝1 提问4 回答
  • Dingda

    Dingda · 站长 (已认证)

    4 粉丝0 提问3 回答
  • 螃蟹居

    1 粉丝0 提问2 回答

扫码关注云+社区

领取腾讯云代金券