创建DEF检查是否找到URL是否是VAILD,请转到其他URL来编辑该字段,但请检查当前的URL,然后提取正确的信息



尝试创建DEF检查URL是否有效,如果找不到该URL,请按下其他URL按下按钮以编辑该字段,但请检查当前URL,然后从配置中拉出正确的信息并发送到文本字段以下是我正在看的

<tbody><tr>
                    <th width="150">License Key *</th>
                    <td width="1">:</td>
                    <td><input type="text" name="LicenseKey" value="" size="80" maxlength="64"></td>
                </tr>
                </tbody>

>

def licenses(value):
    try:
        gotoURL(builder+value)
        if driver.find_element_by_xpath('//*[@id="main-message"]/h1/span'):
            gotoURL(base_url+value)
        if driver.find_element_by_xpath('//*[@id="main-message"]/h1/span'):
            gotoURL(server1+value)
        if driver.find_element_by_xpath('//*[@id="main-message"]/h1/span'):
            gotoURL(server2+value)
    except NoSuchElementException:
        pressButton(license_edit)
        if driver.current_url(builder):
            sendKeys(license_key,server_license)
        if driver.current_url(base_url):
            sendKeys(license_key,serverlicense)
        if driver.current_url(zach_server):
            sendKeys(license_key,server_license1)
        if driver.current_url(michael_server):
            sendKeys(license_key,server_license2)

这是我遇到的错误

我猜你正在得到typeError,因为

driver.find_element_by_xpath() 

返回一个网络元素,无论出于何种原因,它都无法转换为if语句的布尔值。尝试切换到

driver.find_elements_by_xpath()

即使仅找到一个元素,此方法仍然可以正常工作,它只是返回包含该元素的数组。这很重要,因为Python能够看到长度1 的数组(如果找到一个或多个元素)并将其转换为boolean。

最新更新