function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Robin BarnwellRobin Barnwell 

Accessing Salesforce fields with Selenium

I'm trying to access the Search bar in Classic with Selenium but cannot seem to find the object.  I've tried a few variants below, how do I access?

driver.findElement(By.name("str")).sendKeys("Hello");
driver.findElement(By.xpath("//*[@id='phSearchInput']")).sendKeys("Hello");
driver.findElement(By.id("phSearchInput")).sendKeys("Hello");
Best Answer chosen by Robin Barnwell
Basim TariqBasim Tariq
Good morning and Happy Sunday! Thank you so much! This worked! I spent all Friday night and all Saturday and woke up this morning to such a lovely surprise! I cannot believe this worked! I actually have tears of happiness, because I am so relived and happy. Robin, I want you to know that I will be saying a very special prayer for you. You have made my day. I recently joined this project as a tester. I have a strong UFT background, which is what the project was supposed to be on. However leadership wants an open source solution aka Selenium. I just started learning selenium a week ago and I know it will be an uphill battle. On top of that I will be becoming a father soon. Your gesture and guidance has given me hope. I wish you could see the huge smile on my face ☺! Once again thank you! Also would it be okay for me to contact you for any other questions? I promise to keep them simple and I promise to do my own research first before asking anything. Don’t feel pressured to say yes, but it would mean the world to me! Thank you again and may god bless with you never ending happiness. Sincerely, Basim

All Answers

Robin BarnwellRobin Barnwell
It's OK, I've solved it!
Basim TariqBasim Tariq
Hello, I am facing the same issue. I am very new to salesforce and even newer to Selenium. I have tried everything. I have tried finding the object by its name, id, xpath etc. What did you do to get this issue resolved? Please help, and god bless 
Basim TariqBasim Tariq
Here is an example of what I have used

    driver.findElement(By.xpath("//*[@id=\'phSearchInput\']")).sendKeys("TEST");
    driver.findElement(By.id("phSearchInput")).sendKeys("TEST");
    driver.findElement(By.cssSelector("#phSearchInput")).sendKeys("Test");
Robin BarnwellRobin Barnwell
The issue for me was I was trying to access the element too early.  The page was still loading.  Here is the magic line of code that worked for me:
 
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
 .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='phSearchInput']")));

Please let me know if this fixes the issue
Basim TariqBasim Tariq
Good morning and Happy Sunday! Thank you so much! This worked! I spent all Friday night and all Saturday and woke up this morning to such a lovely surprise! I cannot believe this worked! I actually have tears of happiness, because I am so relived and happy. Robin, I want you to know that I will be saying a very special prayer for you. You have made my day. I recently joined this project as a tester. I have a strong UFT background, which is what the project was supposed to be on. However leadership wants an open source solution aka Selenium. I just started learning selenium a week ago and I know it will be an uphill battle. On top of that I will be becoming a father soon. Your gesture and guidance has given me hope. I wish you could see the huge smile on my face ☺! Once again thank you! Also would it be okay for me to contact you for any other questions? I promise to keep them simple and I promise to do my own research first before asking anything. Don’t feel pressured to say yes, but it would mean the world to me! Thank you again and may god bless with you never ending happiness. Sincerely, Basim
This was selected as the best answer
Robin BarnwellRobin Barnwell
No problem, glad it worked.  It took me a few days to work it out!