我有一个内部Web应用程序,它有一个模态对话框.不幸的是,我不能在这里发布实际的Web应用程序位置,但让我尽可能地描述它.
我可以点击固定次数(例如:如果我知道有两个页面我可以点击两次)但我不确定如何改变它以便无论我有多少页面它都会运行.我想要一个普遍的解决方案; 据推测,这会使用某种循环来检查按钮是否已启用.如果是,则单击它.如果它被禁用,则退出循环.
问题是:如何在Selenium中设置循环,重复单击按钮直到它被禁用?
这是我尝试过的代码:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
# Create a new instance of the Firefox driver
driver = webdriver.Firefox()
driver.get("http://localhost/myapp")
try:
wait = WebDriverWait(driver, 100)
wait.until(EC.element_to_be_clickable((By.ID,'menuIntroBox_buttonNext')))
driver.find_element_by_id("menuIntroBox_buttonNext").click()
# Click through the introduction text... this is the problematic code.
# Here I tried to wait for the element to …Run Code Online (Sandbox Code Playgroud) 给定一个字符串,以及该字符串中的字符偏移量,我可以使用Python正则表达式向后搜索吗?
我试图解决的实际问题是在字符串中的特定偏移处获得匹配的短语,但我必须匹配该偏移之前的第一个实例.
在我有一个长度为一个符号的正则表达式的情况下(例如:单词边界),我正在使用一个解决方法来反转字符串.
my_string = "Thanks for looking at my question, StackOverflow."
offset = 30
boundary = re.compile(r'\b')
end = boundary.search(my_string, offset)
end_boundary = end.start()
end_boundary
Run Code Online (Sandbox Code Playgroud)
产量:33
end = boundary.search(my_string[::-1], len(my_string) - offset - 1)
start_boundary = len(my_string) - end.start()
start_boundary
Run Code Online (Sandbox Code Playgroud)
产量:25
my_string[start_boundary:end_boundary]
Run Code Online (Sandbox Code Playgroud)
输出:'问题'
但是,如果我有一个可能涉及多个字符的更复杂的正则表达式,这种"反向"技术将无法工作.例如,如果我想匹配在指定偏移量之前出现的第一个"ing"实例:
my_new_string = "Looking feeding dancing prancing"
offset = 16 # on the word dancing
m = re.match(r'(.*?ing)', my_new_string) # Except looking backwards
Run Code Online (Sandbox Code Playgroud)
理想输出:喂食
我可以使用其他方法(将文件拆分为行,并向后遍历行)但向后使用正则表达式似乎是一个概念上更简单的解决方案.
我在R中有一个数据框,我想使用reshape2库进行融合.有两个原因.
我想使用ggplot绘制条形图中每个问题的每个用户的分数.
我想把这些数据放到Excel中,这样我就可以看到,每个用户,他们的情绪,分数,以及混合的动机,态度,等等.我的意图是使用融合,然后转换为将数据放入宽格式以便于Excel导入.
当我尝试运行熔化时,我收到一个警告,最终在我生成的熔融数据框中出现了NA.
Warning messages:
1: In `[<-.factor`(`*tmp*`, ri, value = c(0.148024, 0.244452, -0.00421, :
invalid factor level, NAs generated
2: In `[<-.factor`(`*tmp*`, ri, value = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, :
invalid factor level, NAs generated
Run Code Online (Sandbox Code Playgroud)
我最终在我的融合数据框中输入了大量的NA.我认为这是因为我在同一列中同时使用了字符和数字.
结果我有两个问题.
问题1:R中是否有解决方法?
问题2:我是否有更好的方法来构建数据以避免此问题?
这是我创建数据框的代码.
words <- data.frame(read.delim("sentiments-test-subset-no-text.txt", header=FALSE))
names(words) <- c("level", "question", "user", "sentiment", "score", "mixed")
words$user <- as.factor(words$user)
words.m <- melt(words, id.vars=c("user", "level"), measure.vars=c("sentiment", "score", "mixed"))
Run Code Online (Sandbox Code Playgroud)
我很难重塑和融化,但我认为这就是我想要的最后一行.
人类可读格式的数据如下所示.
experimental motivated 1 …Run Code Online (Sandbox Code Playgroud)