因为Webdriver在进入下一行之前等待整个页面加载,我认为禁用图像,css和javascript会加快速度.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
def disableImages(self):
## get the Firefox profile object
firefoxProfile = FirefoxProfile()
## Disable CSS
firefoxProfile.set_preference('permissions.default.stylesheet', 2)
## Disable images
firefoxProfile.set_preference('permissions.default.image', 2)
## Disable Flash
firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
'false')
## Set the modified profile while creating the browser object
self.browserHandle = webdriver.Firefox(firefoxProfile)
Run Code Online (Sandbox Code Playgroud)
我从stackoverflow获取代码不希望加载图像和使用Python在Selenium WebDriver测试中在Firefox上渲染CSS
但是当我补充说
driver = webdriver.Firefox()
driver.get("http://www.stackoverflow.com/")
Run Code Online (Sandbox Code Playgroud)
到最后,它仍然加载图像:/
driver = webdriver.Firefox() #opens firefox
driver.get("https://www.google.com/") #loads google
Run Code Online (Sandbox Code Playgroud)
如果加载谷歌需要太长时间,如何让它关闭浏览器并从头开始代码?
在深入研究堆栈溢出后,我发现了一些代码来检查字符串是否为字母数字且超过 8 个字符。它工作得很好。现在,如果它包含至少 2 个数字,我该如何让它返回 true?我想我必须在\d{2}
某处添加。
String pattern = "^[a-zA-Z0-9]*$";
if (s.matches(pattern) && s.length() >= 8){
return true;
}
return false;
Run Code Online (Sandbox Code Playgroud) 我试图迭代地计算e,但是我的代码给了我2.知道什么可能是错的?因为我完全卡住了.
public class iteratee {
public static void main(String[] args) {
long limit = 0;
for (int i = 0; i < 11; i++) {
limit = limit + 1/factorial(i);
}
System.out.println(limit);
}
static int factorial(int n) {
int factorial = 1;
for (int j = 1; j <= n; j++) {
factorial = factorial * j;
}
return factorial;
}
}
Run Code Online (Sandbox Code Playgroud) for (int i = 0; i <= (line.length()/2); i++) { \\loops from the first character until the character in the middle
if (line.charAt(i) != line.charAt(line.length() - i)) { \\checks if 1st character of line is not equal to the last character, and so on..
System.out.println("Entered string is not a palindrome.");
return; \\ends program, no need to check anything else
}
}
System.out.println("Entered string is a palindrome.");
Run Code Online (Sandbox Code Playgroud)
我不断得到索引超出范围错误
java ×3
python ×2
selenium ×2
css ×1
firefox ×1
javascript ×1
palindrome ×1
regex ×1
timeout ×1
webdriver ×1