I am trying to extract IP address information from a webpage using Selenium, here is a portion of the code
removals = []
ServerNames = driver.find_elements_by_xpath("//span[contains(text(), 'Microsoft') or contains(text(), 'Solaris') or contains(text(), 'Linux') or contains(text(), 'Server') or contains(text(), 'Windows') or contains(text(), 'AIX') or contains(text(), 'VMware') or contains(text(), 'ESX')]")
Backups = driver.find_elements_by_xpath("//span[contains(text(), '|locationInherited=true')]")
ips = driver.find_elements_by_xpath("//span[contains(text(), '10.') or contains(text(), '167.') or contains(text(), '170.') or contains(text(), '192.') or contains(text(), '172.') or contains(text(), '204.')]")
for x, y in itertools.zip_longest(ServerNames, Backups, fillvalue=''):
x.click()
ips
y.click()
ips
for ip in ips:
removals.append(ip.text)
When a 'ServerNames' object is found and clicked, the webpage will display both the primary and backup IP addresses for that particular server, with that said, need the script to:
1)Iterate through every found "ServerNames" object 2) Click on the object 3) Grab the associated Primary IP 4) Click on the associated "Backups" object found 5) Grab that IP as well
Then move on to the next ServerNames object and repeat these steps until all IP addresses for all severs have been extracted. I understand that the driver.find_elements method essentially create lists, so basically I need a way to alternate clicking & extracting data for each iteration through the lists. Thanks,
with the code above I get this error:
c:\Python35\Scripts>python Remedy2.py
Traceback (most recent call last):
File "Remedy2.py", line 73, in <module>
y.click()
AttributeError: 'str' object has no attribute 'click'
with this code:
for x in ServerNames:
x.click()
ips = driver.find_elements_by_xpath("//span[contains(text(), '10.') or contains(text(), '167.') or contains(text(), '170.') or contains(text(), '192.') or contains(text(), '172.') or contains(text(), '204.')]")
if Backups:
for y in Backups:
y.click()
ips = driver.find_elements_by_xpath("//span[contains(text(), '10.') or contains(text(), '167.') or contains(text(), '170.') or contains(text(), '192.') or contains(text(), '172.') or contains(text(), '204.')]")
I get a 'stale element error'