我正在尝试在Selenium/Python中运行一个脚本,在脚本的其余部分可以运行之前需要在不同的位置登录.有没有办法告诉脚本暂停并在登录屏幕上等待用户手动输入用户名和密码(可能是在继续脚本之前等待页面标题更改的东西).
到目前为止这是我的代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import unittest, time, re, getpass
driver = webdriver.Firefox()
driver.get("https://www.facebook.com/")
someVariable = getpass.getpass("Press Enter after You are done logging in")
driver.find_element_by_xpath('//*[@id="profile_pic_welcome_688052538"]').click()
Run Code Online (Sandbox Code Playgroud) 我正在尝试找到位于另一个窗口中打开的窗口中的元素的xpath,以便在selenium的python脚本中使用.
该页面本质上是一个框架,在其中托管另一个页面(想想浏览器窗口中的浏览器).
我可以在外部浏览器窗口中找到窗口本身的xpath,但我似乎无法使用xpath选择内部窗口中的任何元素.
这是选择我想要的元素的整体xpath.
/html/body/div/div[2]/table/tbody/tr/td[2]/form/div/div/div/div/div/table[2]/tbody/tr/td/div/div/div/div/div[2]/div/span/iframe/html/body/table/tbody/tr/td/div[3]/div[2]/div[2]/table/tbody/tr/td[2]/div/a[1]
选择内部窗口的xpath是:
/html/body/div/div[2]/table/tbody/tr/td[2]/form/div/div/div/div/div/table[2]/tbody/tr/td/div/div/div/div/div[2]/div/span/iframe
选择内部窗口内项目的xpath(如果直接在内部窗口的页面上)是:
/html/body/table/tbody/tr/td/div[3]/div[2]/div[2]/table/tbody/tr/td[2]/div/a[1]
我已尝试使用所有这些方法,但无法在内页上选择元素.
这是Python代码:
survivorFrame = driver.find_elements_by_xpath(".//*[@id='theSurvivorIframe']")[0]
driver.switch_to_frame(survivorFrame)
elem1 = driver.find_elements_by_xpath(".//*[@id='lea1_ileinner']/a[1]")
survivorOwner = re.search('>(.*)<', elem1)
print elem1
print survivorOwner
Run Code Online (Sandbox Code Playgroud) 我想编写一个脚本,每天删除一次电子表格中的所有过滤器.
我无法找到有关如何在Google Apps脚本中处理过滤的任何好文档.
如果可能的话,我也愿意使用Python API来做这件事.
尝试在Python中将数据写入CSV时,我收到以下错误.
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/csv.py", line 150, in writerows
UnicodeEncodeError: 'ascii' codec can't encode character u'\xd3' in position 0: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
以下是我尝试写入CSV的字典示例:
{'Field1': 'Blah \xc3\x93 D\xc3\xa1blah', 'Field2': u'\xd3', 'Field3': u'Blah', 'Field4': u'D\xe1blah'}
Run Code Online (Sandbox Code Playgroud)
我知道你不能使用Python将unicode写入CSV,但是我无法弄清楚要转换的内容以及如何转换它.
编辑:这是我试过的. dictList是从另一个CSV中获取的词典列表.
WANTED_HEADERS = ['First Name',
'Last Name',
'Date',
'ID']
def utf8ify(d):
return dict((str(k).encode('utf-8'), str(v).encode('utf-8')) for k, v in d.iteritems())
def ListToCSVWithHeaders(data_list, output_file_name, headers):
output_file = open(output_file_name, 'w')
header_row = {}
to_append = []
for entry in data_list:
to_append.append(utf8ify(entry))
for key in entry.keys():
if key …Run Code Online (Sandbox Code Playgroud)