I am very new to coding - We are using Selenium with python scripting.
Please find the attached screen shot for the HMTL of my page.
The actual web page is a table that has "x" for all the user accounts.
I am trying to locate the href attribute that contains a user account that I pass as variable.(In the below example I am trying to click on the link that has "expample#exampleemail.com" )
Can someone please help me locating the element.
Thanks!
You can find the element by xpath:
text = "example#example.com"
element = driver.find_element_by_xpath('//a[contains(#href, "%s")]' % text)
I've answered a similar question here...
In your case, just translate the java to python.
driver.find_element_by_css_selector("a[href*='example#example.com']")
Related
I have a question.
I am trying to access a search field with Selenium, but this has no name and no ID in the html code.
Does anyone know how I can get the search field so that I can write something in it with selenium?
Html Code of the search field
Complete Html Code
You can write the xpath for that like from you screenshot:
//input[#type='text']
You can learn more about xpath from here
I am try to locate and click the link using selenium.
The html is as follows:
21
On the webpage, the number 21 appears as a hyperlink and will bring to next page when clicked.
I tried using xpath to a href and partial link text to "21" but it didn't work.
Any ideas on how to click that link?
you can use contains sample usage:
//body[contains(#Attribute,'value')]
for you:
//a[contains(text(),'21')].click()
note:(it is normally written as "#Attribute" but, "text" is not exactly "Attribute" so "#" is not used)
I've been trying to create a Python Selenium script to reply to facebook wall posts.
I'll be naive in describing the problem since I'm learning both python, selenium and HTML as a beginner.
I'm not able to find a clickable element in my wall and click on the element. When I do manually click, there is a JS element which seems to create an editable element where I can write my comment as reply.
But finding the element to click is really tricky. Any help would be appreciated.
Here is the code snippet I've used.
mydriver.get(baseurl)
mydriver.maximize_window()
mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).clear()
mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).send_keys(username)
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).clear()
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).send_keys(password)
mydriver.find_element_by_xpath(xpaths['submitButton']).click()
post_box = mydriver.find_element_by_css_selector(".UFIAddCommentInput")
ActionChains(mydriver).move_to_element(post_box).click().perform()
print("InputContainer Selected")
post_box=mydriver.find_element_by_xpath("//*[#class='_1mf _1mj']")
post_box.send_keys("Testing using Name not ID. Selenium is easy.")
post_box.send_keys(Keys.ENTER)
print ("Posted...")
Here is where I'm trying to register the comment.
http://prntscr.com/bsxmsm
Thanks in advance.
I want to scrape the email address from the following web page.
Facebook Business Info Page
So I decided to use the selenium driver with Python. I figured the best way to do this was through defining the xpath. From inspection of the elements, I noticed that the info I was looking for was found in the following HTML structure as seen here:
Now I must admit that I am bit of a noob when it comes to using Selenium and defining elements by xpath, so I was hoping someone would correct me if I am defining the following xpath incorrectly. This is what I have right now:
But I'm fairly certain I'm defining the wrong xpath. I know I want to grab the information in the _50f4 div class but I don't know how to define it. If someone could help me figure that out I would greatly appreciate it.
you can get the text of the email address using an xpath like : //div[#id = 'u_0_u']//ul/li[4]//div[#class = '_50f4']
I'm using selenium with python to click a link input by a user on a form that looks something like this.
Please link your facebook (e.g. facebook.com/xxxxxx):
facebook.com/sampleuserinput
I need a python script that only clicks the link provided by the user (facebook.com/sampleuserinput) and not the sample link (facebook.com/xxxxxx).
Both of these links are together in 1 text box (same xpath).
There are two links in a text box? Could you clarify or show some HTML?
I suggest you look at elem = driver.find_element_by_link_text("foo") to get an anchor element by the text of the link. Then click it with elem.click().
There is all sorts of good documentation for selenium with examples for a variety of languages.