2015-05-26 35 views
1

试图使用简单的对话框输入信息,但它不允许我使用我在对话框中输入的fieldValuePython无法输入字段值作为字符串

错误如下消息:

driver.get("https://" + fieldValues + "/test/") 

TypeError: cannot concatenate 'str' and 'tuple' objects

脚本如下:

import re 
import easygui 
from pprint import pprint 
from selenium import webdriver 
from pyvirtualdisplay import Display 
from selenium.webdriver.common.keys import Keys 


msg = "Please enter the server to test...", 
title = "Local Server Tester ", 
fieldNames = ['Server URL'], 
fieldValues = [], # we start with blanks for the values 
fieldValues = easygui.multenterbox(msg,title, fieldNames), 



# Get server from fieldValues 
print ("Server to test", (fieldValues)) 


# Log into system 

driver = webdriver.Chrome() 
driver.get("https://" + fieldValues + "/test") 
+0

尝试'''.join(list(fieldValues))' – farhawa

+0

'fieldValues'里面有什么和你想要的? –

+0

Inside fieldValues将会被输入到对话框中,例如'google.com' – Grimlockz

回答

0

修改这条线,它应该工作,(如果你只有一个网址进行测试)

driver.get("https://" + fieldValues[0][0]+ "/test") 

你fieldValue方法是寻找类似this.It是具有单一的字符串

列表的元组10
FieldValues= (['www.yourserver.com'],) 
0

如果你想这个tuple添加到新string,你可以从它创建一个字符串:

driver.get("https://" + str(fieldValues) + "/test/") 

您应该确保fieldValues的字符串表示形式是您真正想要的,并且如果不写一个函数来解开元组,并从其元素中创建格式正确的字符串。

编辑:在有限的情况下,你可能正在寻找这样的事情把它解析值,并将其与分离,假设fieldValues是一个域名的部分“”:

driver.get("https://" + '.'.join(fieldValues) + "/test/") 
相关问题