Selenium IDE SelectWindow

时间:2014-02-27 21:12:27

标签: selenium-ide

我搜索过以前的帖子但未能找到解决方案,所以我会尝试新帖子。

我有一个简单的登录页面,在按下按钮后,它会将您发送到一个新窗口。我试图选择这个新窗口,然后断言它的标题,但Selenium IDE找不到带标题的Window。

以下是此新窗口标题的HTML代码...

<head><title>
    Pharma Unified Access: Main Menu
</title>

我的Selenium代码很简单。

<tr>
    <td>selectWindow</td>
    <td>Pharma Unified Access: Main Menu</td>
    <td></td>
</tr>
<tr>
    <td>assertTitle</td>
    <td>Pharma Unified Access: Main Menu</td>
    <td></td>
</tr>

我收到以下消息......

[错误]窗口不存在。如果这看起来像Selenium bug,请务必阅读http://seleniumhq.org/docs/02_selenium_ide.html#alerts-popups-and-multiple-windows以获取可能的解决方法。

我使用了storeallwindownames / ids / title,而Selenium甚至不识别新窗口的存在,因为它只给出了原始窗口的名称/标题/ id?如何让Selenium IDE识别出这个新窗口的存在?

非常感谢任何帮助。

3 个答案:

答案 0 :(得分:0)

您是否有权编辑HTML代码。可能是标题中存在隐藏字符,例如\ n \ n \ n换行符\ t \ t tab。

您是否可以将HTML代码更改为Pharma Unified Access:主菜单,或者尝试添加通配符以覆盖任何隐藏字符。

<tr>
    <td>selectWindow</td>
    <td>*Pharma Unified Access: Main Menu*</td>
    <td></td>
</tr>

答案 1 :(得分:0)

如果你碰巧有窗口ID,你可以试试这个:

<tr>
    <td>openWindow</td>
    <td></td>
    <td>windowID</td>
</tr>
<tr>
    <td>assertTitle</td>
    <td>Pharma Unified Access: Main Menu</td>
    <td></td>
</tr>

建议使用此命令作为bug SEL-339的解决方法。

答案 2 :(得分:0)

您面临的问题是selenium IDE中存在一个错误,它只能识别IT打开的窗口。您无法使用“selectWindow”选择新窗口,因为Selenium IDE没有“打开”窗口。它在链接上“点击”,网页“打开”了窗口。

解决方法是在指向@href的超链接元素上使用storeAttribute从链接中提取url并将其存储为变量。然后使用openWindow。所以而不是:

Private Sub criargraf()
Dim cont, cont2 As Integer

Application.ScreenUpdating = False

If Sheets("SubUN").ChartObjects.Count > 0 Then
        Sheets("SubUN").ChartObjects.Delete
End If

Sheets("SubUN").Shapes.AddChart

Set graf = Sheets("SubUN").ChartObjects(1)

If graf.Chart.SeriesCollection.Count > 0 Then

    cont = graf.Chart.SeriesCollection.Count

        Do While cont > 0

        graf.Chart.SeriesCollection(1).Delete 'às vezes,Quando se cria um gráfico, este já vem com uma série, portanto tens de fazer um Newseries a menos
        cont = cont - 1

        Loop

    End If

    With graf.Chart

        .ChartArea.Width = 878
        .Parent.Height = 470
        .Parent.Top = 37
        .Parent.Left = 575

        .HasLegend = True
        .Legend.Left = 215
        .Legend.Top = 400
        .Legend.Height = 100
        .Legend.Width = 500

        .PlotArea.Height = 350
        .PlotArea.Width = 830

        .PlotArea.Left = 20
        .PlotArea.Top = 30


        .ChartType = xlLine
        .HasTitle = True
        .ChartTitle.Characters.Text = Range("E134")
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Meses"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = Range("E131")
    End With

    cont = 1
    cont2 = 1

    Do While Range("L" & 121 + cont).Value <> ""
        If Sheets("SubUN").Rows(120 + cont).EntireRow.Hidden = False Then
            With graf.Chart
                .SeriesCollection.NewSeries
                .SeriesCollection(cont2).Values = Sheets("SubUN").Range("M" & (120 + cont) & ":X" & (120 + cont))
                .SeriesCollection(cont2).Name = Sheets("SubUN").Range("L" & (120 + cont))
                .SeriesCollection(cont2).XValues = Range("M120:X120")
            End With
            cont2 = cont2 + 1
        End If
    cont = cont + 1

    Loop

    cont = 1
    Do While Range("L" & 145 + cont).Value <> ""
        If Sheets("SubUN").Rows(145 + cont).EntireRow.Hidden = False Then
            With graf.Chart
                .SeriesCollection.NewSeries
                .SeriesCollection(cont2).Values = Sheets("SubUN").Range("M" & (145 + cont) & ":X" & (145 + cont))
                .SeriesCollection(cont2).Name = Sheets("SubUN").Range("L" & (145 + cont))
                .SeriesCollection(cont2).XValues = Range("M145:X145")
            End With
            cont2 = cont2 + 1
        End If
    cont = cont + 1

    Loop



    cont = 1
    Do While Range("L" & 168 + cont).Value <> ""
        If Sheets("SubUN").Rows(168 + cont).EntireRow.Hidden = False Then
            With graf.Chart
                .SeriesCollection.NewSeries
                .SeriesCollection(cont2).Values = Sheets("SubUN").Range("M" & (168 + cont) & ":X" & (168 + cont))
                .SeriesCollection(cont2).Name = Sheets("SubUN").Range("L" & (168 + cont))
                .SeriesCollection(cont2).XValues = Range("M168:X168")
                .SeriesCollection(cont2).AxisGroup = xlSecondary
                .SeriesCollection(cont2).ChartType = xlColumnClustered
                .SeriesCollection(cont2).ApplyDataLabels
                '.SeriesCollection(cont2).DataLabels.Position = xlLabelPositionAbove

            End With

            cont2 = cont2 + 1

        End If

        cont = cont + 1

    Loop

   If cont2 > 2 Then

   graf.Chart.HasAxis(xlValue, xlSecondary) = True
   With graf.Chart
        '.Legend.Left = 2000 * (cont2) ^ -1
        .Legend.Width = 100 * (cont2)
        .Axes(xlValue, xlSecondary).HasTitle = True
        .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = " Variação (%)"
        .Axes(xlValue).HasMajorGridlines = True
        .Axes(xlValue).MajorGridlines.Border.LineStyle = xlDashDotDot
        .Axes(xlValue).MajorGridlines.Border.Color = RGB(190, 190, 190)

    End With
    End If

End Sub

使用这种策略:

import ldap
import os
import subprocess
import uuid
from pwd import getpwnam

# Lookup all the users in the cloud group
path='dc=saao'
l=ldap.open('ldap1.cape')
l.protocol_version = ldap.VERSION3
l.simple_bind('dc=cape')
a=l.search_s(path,ldap.SCOPE_SUBTREE,'cn=cloudcape')

# Add members to uids
uids=a[0][1]['memberUid']

# Check if a bindmount already exists or it not, that each cloud group user has the required directory i.e. /home/USER/cloud and /var/www/owncloud/data/USER/files
for uid in uids:
    cloudfiledir="/var/www/owncloud/data/"+uid+"/files"
    clouddir="/home/"+uid+"/cloud"
    try:
        subprocess.check_output(["mountpoint", cloudfiledir])
        # If the output is all good, their bind mount is setup and mounted
        break
    except:
        print uid+" has not logged into ownCloud yet - please ask them to do so and then try again"
        break
    # Now check if they have the required directories
    try:
        if os.path.isdir(cloudfiledir):
            print "user "+ uid +" has a data directory in the owncloud data directory- this is good."
            if os.path.isdir("/home/"+uid+"/cloud"):
                print "user "+ uid +" has a cloud dir in their home directory - this is good."
            else:
                # They don't have a cloud directory, creating one
                print uid+" does not have a cloud folder in their home directory, creating it"
                if not os.path.exists("/home/"+uid+"/cloud"):
                    os.makedirs("/home/"+uid+"/cloud")
                    # Now set permissions ("+uid+":Domain Users) - os.chown(path, uid, gid)
                    os.chown("/home/"+uid+"/cloud", "+uid+", "Domain Users")
                else:
                    break
                # Now make sure the cloufilesdir is empty
                if not os.listdir(cloudfiledir):
                    print "Empty"
                    break
except:
    print "rename and recreate the folder"
    os.rename(clouddir, clouddir + str(uuid.uuid4()))
    os.makedirs(clouddir)
    os.chown(clouddir, 33, 33)

print "Now let's bind mount the directories"

# Bind each users home dir to their cloud dir
# Eg: bindfs -M www-data --create-for-user=1168 --create-for-group=513 /home/simon/cloud /var/www/owncloud/data/simon/files
# Still figuring this bit out
for user in a[0][1]['memberUid']:
    filt = "(uid=" + user + ")"
    u=l.search_s(path, ldap.SCOPE_SUBTREE, filt, ['uidNumber'])
    print "\t", user, "filter: ", filt, u,  "or"
    uid = u[0][1]['uidNumber'][0]
    print "\t\t", user, filt, uid
    command = 'bindfs -M www-data --create-for-user=' + uid + ' --create-for-group=513 ' + '/home/' + user + '/cloud' + ' /var/www/owncloud/data/' + user + '/files'
    print "BINGO: ", command, "\n"

希望有所帮助。