Python 硒可见、不可见元素(下拉)
我正在尝试选择下拉列表的所有元素 我正在测试的站点是: 我试图访问的下拉列表(复选框列表)是“位置”列表 我正在使用Python。我收到以下错误:消息:u'Element当前不可见,因此可能无法与' 我使用的代码是:Python 硒可见、不可见元素(下拉),python,selenium,visible,mousemove,invisible,Python,Selenium,Visible,Mousemove,Invisible,我正在尝试选择下拉列表的所有元素 我正在测试的站点是: 我试图访问的下拉列表(复选框列表)是“位置”列表 我正在使用Python。我收到以下错误:消息:u'Element当前不可见,因此可能无法与' 我使用的代码是: from selenium import webdriver url = "http://jenner.com/people" driver = webdriver.Firefox() driver.get(url) page = drive
from selenium import webdriver
url = "http://jenner.com/people"
driver = webdriver.Firefox()
driver.get(url)
page = driver.page_source
element = driver.find_element_by_xpath("//div[@class='filter offices']")
elements = element.find_elements_by_tag_name("input")
counter = 0
while counter <= len(elements) -1:
driver.get(url)
element = driver.find_element_by_xpath("//div[@class='filter offices']")
elements1 = element.find_elements_by_tag_name("input")
elements1[counter].click()
counter = counter + 1
从selenium导入webdriver
url=”http://jenner.com/people"
driver=webdriver.Firefox()
获取驱动程序(url)
page=driver.page\u源
element=driver。通过xpath(//div[@class='filter offices'])查找元素
元素=元素。通过标记名称(“输入”)查找元素
计数器=0
虽然计数器作为输入复选框在初始状态下不可见,但单击“筛选办公室”选项后,它们将可见。类名也将从“筛选办公室”更改为“筛选办公室打开”,如果您在firebug中观察到,下面的代码对我来说很有用,但它是Java的。但是您可以理解python,因为它包含真正的基本代码
driver.get("http://jenner.com/people");
driver.findElement(By.xpath("//div[@class='filter offices']/div")).click();
Thread.sleep(2000L);
WebElement element = driver.findElement(By.xpath("//div[@class='filter offices open']"));
Thread.sleep(2000L);
List <WebElement> elements = element.findElements(By.tagName("input"));
for(int i=0;i<=elements.size()-1;i++)
{
elements.get(i).click();
Thread.sleep(2000L);
elements = element.findElements(By.tagName("input"));
}
driver.get(“http://jenner.com/people");
findElement(By.xpath(“//div[@class='filter offices']]/div”)。单击();
睡眠(2000L);
WebElement=driver.findElement(By.xpath(“//div[@class='filter offices open']);
睡眠(2000L);
列表元素=element.findElements(按.tagName(“输入”));
对于(int i=0;i我知道这是一个老问题,但我在寻找其他信息时遇到了它。我不知道您是否在网站上进行QA,以查看下拉列表中是否显示了适当的城市,或者您是否实际与网站互动,以获取每个位置的人员列表。(旁注:如果不重置过滤器,则选择位置然后取消选择将返回0个结果-可能不是所需的行为。)
如果你想在这个网站上获取每个位置的用户列表,我认为不使用Selenium会更容易。这里有一个非常简单的解决方案,可以把人们从第一个城市“芝加哥”拉出来。当然,你可以列出你应该寻找的城市,并将他们分到“数据”中通过在列表中循环使用变量
import requests
from bs4 import BeautifulSoup
url = 'http://jenner.com/people/search'
data = 'utf8=%E2%9C%93&authenticity_token=%2BayQ8%2FyDPAtNNlHRn15Fi9w9OgXS12eNe8RZ8saTLmU%3D&search_scope=full_name' \
'&search%5Bfull_name%5D=&search%5Boffices%5D%5B%5D=Chicago'
r = requests.post(url, data=data)
soup = BeautifulSoup(r.content)
people_results = soup.find_all('div', attrs={'class': 'name'})
for p in people_results:
print p.text
找出python代码伙伴,因为我不知道它。让我知道它对你有用吗。我会的。谢谢Omkar。在你发布后,我今天早上做了一些工作,今天晚些时候会回来。在我可以回去工作之前,今天有一些事情要做。Omkar。你的解决方案对我不起作用。我已经将它转换为python。我想k有两个问题。第一,我有我以前遇到过的相同问题。第二,我没有将此转换从筛选器办公室转换为筛选器办公室打开。单击“位置”后,类名将从“筛选器办公室”更改为“筛选器办公室打开”该动态类名。