HTML of the webpage I am trying to automate
I am trying to click the Link called 'Network'. I used the following statements but I am not able to get to work as it throws me the following error:
Error I get when I run the py script
Here is the command I used:
eleme=driver.find_element_by_xpath("//div[#id='maincontainer']//div[#id='tabmenu']//div[#class='tabmenu1']//ul[#class='tabmenu l1']//li[#class='tabmenu-item-network']//a[#href='Network']")
eleme.click()
Your xpath query is not good (href attribute is incorrect) so element can't be found, try with driver.find_element_by_xpath("//div[#id='maincontainer']//div[#id='tabmenu']//div[#class='tabmenu1']//ul[#class='tabmenu l1']//li[#class='tabmenu-item-network']//a[text()='Network']")
Or even better, driver.find_element_by_xpath("//div[#id='maincontainer']//a[text()='Network']")
EDIT:
You can click on link with driver.find_element_by_link_text('Network')
You should really check WebDriver API http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.remote.webelement
Related
I am trying to scrape the link from a button. If I click the button, it opens a new tab and I can't navigate in it. So I thought I'd scrape the link, go to it via webdriver.get(link) and do it that way since this will be a background program. I cannot find any tutorials on this using the most recent version of selenium. This is in Python
I tried using
wd.find_element("xpath", 'xpath here')
but that just scrapes the button title. Is there a different tag I should be using?
I've also tried just clicking the button but that opens a new tab and I don't know how to navigate on it, since it doesn't work by default and I'm still fairly new to Chromedriver.
I can't use beautifulsoup to my knowledge, since the webpage must be logged in.
You need to get the href attribute of the button. If your code gets the right button you can just use
button.get_attribute("href")
Of course if you get redirected using Javascript this is a different story, but since you didn't specify I will assume my answer works
You can use swith_of function to manage multiple windows(tabs) in same test case session
driver.switch_to.window(name_or_handler)
An extra information: If you want to get attribute value from element, you can use get_attribute() function
link_value = driver.find_element(By, selector).get_attribute("href")
P.S: example code written in Python. If you use another language, you can use equivalent Selenium functions for them.
I'm developing something similar to a webscrapping to take informations from a website in html, but I'm having problems to select the options from the checkbox in the internet web page with selenium webdriver. (I'm using Python 3)
Check out part of the code:
driver.get('website_acessed')
driver.find_element(By.XPATH,'//*[#id="id_presented"]').click()
#this method is presenting this error:
---> 15 driver.find_element(By.XPATH('//*[#id="id_presented"]')).click()
TypeError: 'str' object is not callable
Can someone help me?
Thanks for the attention!
The error you're showing does not match your code.
By.XPATH is indeed a string (By.XPATH='xpath'). So it seems that you're calling driver.find_element(By.XPATH('//*[#id="id_presented"]')) in your code and By.XPATH('//*[#id="id_presented"]') is raising the error.
However, driver.find_element(By.XPATH,'//*[#id="id_presented"]') is indeed the right way to find your element.
i am writing a code on python by using selenium that login into Facebook and Like a Facebook page i requested. it works to login but after opening the Facebook page i requested, it wont like the page it shows error saying 'Attribute-error: 'list' object has no attribute 'click''. maybe it didn't get the correct xpath ,any ideas?
use chropath extension in chrome
See line 27 of your code: you are using find_elementS instead of find_element.
find_elements always returns a list of elements, so when you are trying to do like.click(), it fails. Try using find_element_by_xpath at the line 27 of your code, it should work.
Good luck!
I am trying to click a link by:
driver.find_element_by_css_selector("a[href='javascript:openhistory('AXS0077')']").click()
This works nice if the link opens in a new window but in this case the link actually opens a pop up window. When I try clicking the link with this method, using selenium it gives me an error:
Message: u"The given selector
a[href='javascript:openhistory('AXS0077')'] is either invalid or does
not result in a WebElement. The following error
occurred:\nInvalidSelectorError: An invalid or illegal selector was
specified"
Is this not the right way ? because
I think there may be some different way to deal with pop windows.
Your css selector could be more generic, perhaps:
driver.find_element_by_css_selector("a[href^='javascript']").click()
You've got all kinds of crazy overlapping quotation marks there. You're probably confusing it.
I have more success using find_by_xpath
Take this site as an example popups
I use firebug to inspect the element and get the xpath.
Then using the following works perfectly.
from selenium import webdriver
baseurl="http://www.globalrph.com/davescripts/popup.htm"
dr = webdriver.Firefox()
dr.get(baseurl)
dr.find_element_by_xpath("/html/body/div/center/table/tbody/tr[7]/td/div/table/tbody/tr/td[2]/div[1]/form/table/tbody/tr[4]/td[1]/a").click()
I am very much new to selenium WebDriver and I am trying to automate a page which has a button named "Delete Log File". Using FireBug I got to know that, the HTML is described as
and also the css selector is defined as "#DeleteLogButton" using firepath
hence I used
browser.find_element_by_css_selector("#DeleteLogButton").click() in webdriver to click on that button but its now working and also, I tried,
browser.find_element_by_id("DeleteLogButton").click() to click on that button. Even this did not find the solution for my problem...
Please help me out in resolving the issue.
Most of the times im using By.xpath and it works specially if you use contains in your xpath. For example : //*[contains(text(),'ABC')]
This will look for all the elements that contains string 'ABC'
In your case you can replace ABC with Delete Log File
try to find it by name like :
browser.find_element_by_name("Delete Log File").click();